fix: ensure proper buffer reuse with pointer handling in sync.Pool

This commit is contained in:
2026-01-26 19:50:34 +07:00
parent a3f6baa6ae
commit 7f44cc7bc0
2 changed files with 16 additions and 11 deletions
+4 -3
View File
@@ -46,16 +46,17 @@ func New(config config.Config, slug slug.Slug, conn ssh.Conn) Forwarder {
bufferPool: sync.Pool{
New: func() interface{} {
bufSize := config.BufferSize()
return make([]byte, bufSize)
buf := make([]byte, bufSize)
return &buf
},
},
}
}
func (f *forwarder) copyWithBuffer(dst io.Writer, src io.Reader) (written int64, err error) {
buf := f.bufferPool.Get().([]byte)
buf := f.bufferPool.Get().(*[]byte)
defer f.bufferPool.Put(buf)
return io.CopyBuffer(dst, src, buf)
return io.CopyBuffer(dst, src, *buf)
}
func (f *forwarder) OpenForwardedChannel(ctx context.Context, origin net.Addr) (ssh.Channel, <-chan *ssh.Request, error) {