Close buf writer in event of an error (#6523)

* Close buf writer in event of an error
* Merge refs/heads/master into close-bufwriter
* Merge refs/heads/master into close-bufwriter
This commit is contained in:
terence tsao 2020-07-08 13:03:03 -07:00 committed by GitHub
parent 132ad5beb8
commit 8da0246702
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -151,6 +151,10 @@ func writeSnappyBuffer(w io.Writer, b []byte) (int, error) {
defer bufWriterPool.Put(bufWriter)
num, err := bufWriter.Write(b)
if err != nil {
// Close buf writer in the event of an error.
if err := bufWriter.Close(); err != nil {
return 0, err
}
return 0, err
}
return num, bufWriter.Close()