Skip to content

Commit

Permalink
fix: fix grpc compressor mcache free panic when data is empty (#1364)
Browse files Browse the repository at this point in the history
  • Loading branch information
HeyJavaBean committed May 31, 2024
1 parent 964e56e commit d7fc1df
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions pkg/remote/codec/grpc/grpc_compress.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,10 @@ import (
"errors"
"io"

"github.com/cloudwego/kitex/pkg/rpcinfo"

"github.com/bytedance/gopkg/lang/mcache"

"github.com/cloudwego/kitex/pkg/rpcinfo"

"github.com/cloudwego/kitex/pkg/remote/codec/protobuf/encoding"

"github.com/cloudwego/kitex/pkg/remote"
Expand Down Expand Up @@ -63,7 +63,9 @@ func decodeGRPCFrame(ctx context.Context, in remote.ByteBuffer) ([]byte, error)
}

func compress(compressor encoding.Compressor, data []byte) ([]byte, error) {
defer mcache.Free(data)
if len(data) != 0 {
defer mcache.Free(data)
}
cbuf := &bytes.Buffer{}
z, err := compressor.Compress(cbuf)
if err != nil {
Expand Down

0 comments on commit d7fc1df

Please sign in to comment.