Skip to content

Commit

Permalink
zstd: free Decoder resources when Reset is called with a nil io.Reader
Browse files Browse the repository at this point in the history
Attempt at fixing #296.
  • Loading branch information
mostynb committed Dec 26, 2020
1 parent bb5ba3d commit e44a8d1
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions zstd/decoder.go
Original file line number Diff line number Diff line change
Expand Up @@ -156,8 +156,14 @@ func (d *Decoder) Reset(r io.Reader) error {
if d.current.err == ErrDecoderClosed {
return d.current.err
}

d.drainOutput()

if r == nil {
return errors.New("nil Reader sent as input")
d.current.b = []byte{}
d.current.err = io.EOF
d.current.flushed = true
return nil
}

if d.stream == nil {
Expand All @@ -166,8 +172,6 @@ func (d *Decoder) Reset(r io.Reader) error {
go d.startStreamDecoder(d.stream)
}

d.drainOutput()

// If bytes buffer and < 1MB, do sync decoding anyway.
if bb, ok := r.(*bytes.Buffer); ok && bb.Len() < 1<<20 {
if debug {
Expand Down

0 comments on commit e44a8d1

Please sign in to comment.