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

reset []bytes after getting them from sync.Pool #119

Merged
merged 3 commits into from
Sep 17, 2018
Merged
Show file tree
Hide file tree
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
2 changes: 1 addition & 1 deletion .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ jobs:
if [ "$CIRCLE_BRANCH" == "master" ]; then
printf "\n $CIRCLE_BRANCH branch, ignoring check for relese notes \n"
else
ChangedFiles=`git diff --name-only $CIRCLE_BRANCH origin/master`
ChangedFiles=`git diff --name-only origin/master`
case "$ChangedFiles" in
*RELEASE_NOTES.*)
printf "\n Thanks, your commits include update to release notes. \n";;
Expand Down
1 change: 1 addition & 0 deletions .github/RELEASE_NOTES.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
- removed vendor directory and dep files: https://github.com/komuw/meli/pull/107
- we no longer release meli for 386 arch on github releases.
We now ONLY release amd64 for darwin, linux and windows
- Fixed a bug where buffers from sync.Pool were not reset before use: https://github.com/komuw/meli/pull/119


## v0.1.9.8
Expand Down
6 changes: 6 additions & 0 deletions image.go
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,12 @@ var blackHolePool = sync.Pool{
// this is taken from io.util
func poolReadFrom(r io.Reader) (n int64, err error) {
bufp := blackHolePool.Get().(*[]byte)
// reset the buffer since it may contain data from a previous round
// see issues/118
for i := range *bufp {
(*bufp)[i] = 0

}
readSize := 0
for {
readSize, err = r.Read(*bufp)
Expand Down
12 changes: 12 additions & 0 deletions image_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package meli
import (
"context"
"io/ioutil"
"strings"
"testing"
)

Expand Down Expand Up @@ -91,3 +92,14 @@ func BenchmarkBuildDockerImage(b *testing.B) {
_, _ = BuildDockerImage(ctx, cli, dc)
}
}

func BenchmarkPoolReadFrom(b *testing.B) {
// go test -run=XXX -bench=BenchmarkPoolReadFrom
// BenchmarkPoolReadFrom-4 30000000 36.0 ns/op
// after fixing issues/118: 50.1 ns/op
r := strings.NewReader("hello")
b.ResetTimer()
for n := 0; n < b.N; n++ {
_, _ = poolReadFrom(r)
}
}