Skip to content

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

@yoavj-arpeely

Description

@yoavj-arpeely

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions