pgzip
pgzip copied to clipboard
buf leak in (*Writer).Close()
I use a writer in a loop, which looks like this:
z := gzip.NewWriter(nil)
for {
buf := new(bytes.Buffer)
z.Reset(buf)
msg := getMessage()
z.Write(msg)
z.Close()
processMessage(msg)
}
When closing z, Close() calls compressCurrent(), which gets two buffers from z.dstPool. The second one, in gzip.go:272, is never put back to z.dstPool, since z.init (called from z.Reset) sets z.currentBuffer = nil.
It means that dstPool is not fully utilized, and there are many redundant alllcations
@yoavj-arpeely This library shouldn't be used for small compression tasks, so largely this shouldn't affect anything.
You are welcome to send a PR.