From a9990d59bcc33ca8a98edd21095203635553cdaf Mon Sep 17 00:00:00 2001 From: Graham McIntire Date: Thu, 12 Feb 2026 10:37:34 -0600 Subject: [PATCH] fix staticcheck SA6002: use *[]byte in sync.Pool to avoid allocation --- agent.go | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/agent.go b/agent.go index f75ea69..8eedb2d 100644 --- a/agent.go +++ b/agent.go @@ -120,18 +120,23 @@ func runSession(ctx context.Context, baseURL, token string) error { } bufPool := &sync.Pool{ - New: func() any { return make([]byte, 0, 4096) }, + New: func() any { + b := make([]byte, 0, 4096) + return &b + }, } sendBinaryResult := func(event string, msg proto.Message) { - buf := bufPool.Get().([]byte)[:0] + bp := bufPool.Get().(*[]byte) + buf := (*bp)[:0] bin, err := proto.MarshalOptions{}.MarshalAppend(buf, msg) if err != nil { slog.Error("marshal protobuf", "error", err) return } encoded := base64.StdEncoding.EncodeToString(bin) - bufPool.Put(bin[:0]) + *bp = bin[:0] + bufPool.Put(bp) payload, _ := json.Marshal(map[string]string{"binary": encoded}) sendMsg(event, payload) }