Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

zstd: free Decoder resources when Reset is called with a nil io.Reader #305

Merged
merged 2 commits into from
Dec 30, 2020
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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{}
mostynb marked this conversation as resolved.
Show resolved Hide resolved
d.current.err = io.EOF
klauspost marked this conversation as resolved.
Show resolved Hide resolved
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