Skip to content

Commit

Permalink
fix: remove nil assignments (#18)
Browse files Browse the repository at this point in the history
  • Loading branch information
fionera authored Jun 30, 2022
1 parent f7b4176 commit 9bef87c
Showing 1 changed file with 11 additions and 3 deletions.
14 changes: 11 additions & 3 deletions spooled.go
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,6 @@ func (ms *spooledTempFile) prepareRead() error {
}

ms.mem = bytes.NewReader(ms.buf.Bytes())
ms.buf = nil

return nil
}
Expand Down Expand Up @@ -159,7 +158,10 @@ func (ms *spooledTempFile) Write(p []byte) (n int, err error) {
return
}

ms.buf.Reset()
spooledPool.Put(ms.buf)
ms.buf = nil

if n, err = ms.file.Write(p); err != nil {
ms.file.Close()
ms.file = nil
Expand All @@ -173,9 +175,13 @@ func (ms *spooledTempFile) Write(p []byte) (n int, err error) {

func (ms *spooledTempFile) Close() error {
ms.closed = true
ms.mem = nil

ms.buf.Reset()
spooledPool.Put(ms.buf)
if ms.buf != nil {
ms.buf.Reset()
spooledPool.Put(ms.buf)
ms.buf = nil
}

if ms.file == nil {
return nil
Expand All @@ -187,6 +193,8 @@ func (ms *spooledTempFile) Close() error {
return err
}

ms.file = nil

return nil
}

Expand Down

0 comments on commit 9bef87c

Please sign in to comment.