Prevent bugs caused by multiple Close

See: https://github.com/golang/go/issues/19186
When the body isn't fully read and Close is called multiple times we put
the same buffer in the pool multiple times causing it to be reused by
multiple goroutines at the same time.
This commit is contained in:
Erik Dubbelboer
2017-02-19 06:44:22 +00:00
parent 7a67b2a713
commit e187266de6
+2
View File
@@ -252,6 +252,8 @@ func (r *readCloser) Close() error {
for _, buf := range r.bufs {
putBuf(buf)
}
// In case Close gets called multiple times.
r.bufs = nil
return nil
}