Skip to content

Commit

Permalink
Avoid repeated closures
Browse files Browse the repository at this point in the history
  • Loading branch information
lxzan committed Mar 22, 2024
1 parent e59de96 commit 88589b3
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions internal/pool.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,10 @@ func (c *CloserWrapper) Read(p []byte) (n int, err error) {
}

func (c *CloserWrapper) Close() error {
c.B.Reset()
bytebufferpool.Put(c.B)
c.B, c.R = nil, nil
// 避免重复关闭, 引发panic
if c.B != nil {
bytebufferpool.Put(c.B)
c.B, c.R = nil, nil
}
return nil
}

0 comments on commit 88589b3

Please sign in to comment.