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

pkg/chunkenc: fix leak of pool. #1793

Merged
merged 1 commit into from
Mar 11, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 5 additions & 4 deletions pkg/chunkenc/memchunk.go
Original file line number Diff line number Diff line change
Expand Up @@ -111,10 +111,15 @@ func (hb *headBlock) append(ts int64, line string) error {

func (hb *headBlock) serialise(pool WriterPool) ([]byte, error) {
inBuf := serializeBytesBufferPool.Get().(*bytes.Buffer)
defer func() {
inBuf.Reset()
serializeBytesBufferPool.Put(inBuf)
}()
outBuf := &bytes.Buffer{}

encBuf := make([]byte, binary.MaxVarintLen64)
compressedWriter := pool.GetWriter(outBuf)
defer pool.PutWriter(compressedWriter)
for _, logEntry := range hb.entries {
n := binary.PutVarint(encBuf, logEntry.t)
inBuf.Write(encBuf[:n])
Expand All @@ -132,10 +137,6 @@ func (hb *headBlock) serialise(pool WriterPool) ([]byte, error) {
return nil, errors.Wrap(err, "flushing pending compress buffer")
}

inBuf.Reset()
serializeBytesBufferPool.Put(inBuf)

pool.PutWriter(compressedWriter)
return outBuf.Bytes(), nil
}

Expand Down