From f9730dd2fd5793abc0d4ca70b9893b8823442889 Mon Sep 17 00:00:00 2001 From: Jaewan Park Date: Sat, 25 Feb 2023 13:06:47 +0900 Subject: [PATCH] rpc_util: Copy the buffer only if the pool option is enabled --- rpc_util.go | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/rpc_util.go b/rpc_util.go index 4e91c9126963..821489ad1bb3 100644 --- a/rpc_util.go +++ b/rpc_util.go @@ -767,9 +767,15 @@ func recv(p *parser, c baseCodec, s *transport.Stream, dc Decompressor, m interf if err := c.Unmarshal(buf, m); err != nil { return status.Errorf(codes.Internal, "grpc: failed to unmarshal the received message: %v", err) } - if payInfo != nil && len(buf) != 0 { - payInfo.uncompressedBytes = make([]byte, len(buf)) - copy(payInfo.uncompressedBytes, buf) + if payInfo != nil { + if p.useBytesPool { + if len(buf) != 0 { + payInfo.uncompressedBytes = make([]byte, len(buf)) + copy(payInfo.uncompressedBytes, buf) + } + } else { + payInfo.uncompressedBytes = buf + } } if p.useBytesPool { pool.Put(&buf)