diff --git a/common/bufio/writer.go b/common/bufio/writer.go index 742fb5f7..0ade5f69 100644 --- a/common/bufio/writer.go +++ b/common/bufio/writer.go @@ -85,11 +85,15 @@ func (v *BufferedWriter) SetCached(cached bool) { } } +// Release implements common.Releasable.Release(). func (v *BufferedWriter) Release() { - v.Flush() - - v.buffer.Release() - v.buffer = nil + if !v.buffer.IsEmpty() { + v.Flush() + } + if v.buffer != nil { + v.buffer.Release() + v.buffer = nil + } common.Release(v.writer) }