Skip to content

Commit

Permalink
piecereader: Fix double buffer free
Browse files Browse the repository at this point in the history
  • Loading branch information
magik6k committed May 23, 2023
1 parent f0fec13 commit 5e58f64
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion storage/sealer/piece_provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"bufio"
"context"
"io"
"sync"

"github.com/ipfs/go-cid"
pool "github.com/libp2p/go-buffer-pool"
Expand Down Expand Up @@ -124,13 +125,19 @@ func (p *pieceProvider) tryReadUnsealedPiece(ctx context.Context, pc cid.Cid, se
}
}

var closeOnce sync.Once

return struct {
io.Reader
io.Closer
}{
Reader: bir,
Closer: funcCloser(func() error {
pool.Put(buf)
// this close can be called more than once - double close signals to the paths.Reader that we are done with the piece

closeOnce.Do(func() {
pool.Put(buf)
})
return r.Close()
}),
}, nil
Expand Down

0 comments on commit 5e58f64

Please sign in to comment.