Skip to content

Commit f9730dd

Browse files
committed
rpc_util: Copy the buffer only if the pool option is enabled
1 parent cbaef54 commit f9730dd

File tree

1 file changed

+9
-3
lines changed

1 file changed

+9
-3
lines changed

rpc_util.go

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -767,9 +767,15 @@ func recv(p *parser, c baseCodec, s *transport.Stream, dc Decompressor, m interf
767767
if err := c.Unmarshal(buf, m); err != nil {
768768
return status.Errorf(codes.Internal, "grpc: failed to unmarshal the received message: %v", err)
769769
}
770-
if payInfo != nil && len(buf) != 0 {
771-
payInfo.uncompressedBytes = make([]byte, len(buf))
772-
copy(payInfo.uncompressedBytes, buf)
770+
if payInfo != nil {
771+
if p.useBytesPool {
772+
if len(buf) != 0 {
773+
payInfo.uncompressedBytes = make([]byte, len(buf))
774+
copy(payInfo.uncompressedBytes, buf)
775+
}
776+
} else {
777+
payInfo.uncompressedBytes = buf
778+
}
773779
}
774780
if p.useBytesPool {
775781
pool.Put(&buf)

0 commit comments

Comments
 (0)