Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

buf leak in (*Writer).Close() #56

Open
yoavj-arpeely opened this issue Feb 28, 2024 · 1 comment
Open

buf leak in (*Writer).Close() #56

yoavj-arpeely opened this issue Feb 28, 2024 · 1 comment

Comments

@yoavj-arpeely
Copy link

yoavj-arpeely commented Feb 28, 2024

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

@klauspost
Copy link
Owner

@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.

CorentinB added a commit to CorentinB/warc that referenced this issue Aug 12, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants