Skip to content

Commit

Permalink
Simplify code when pooled buffers aren't returned (#532)
Browse files Browse the repository at this point in the history
  • Loading branch information
pkwarren authored Jun 27, 2023
1 parent 46ff1ed commit daa0efc
Showing 1 changed file with 3 additions and 6 deletions.
9 changes: 3 additions & 6 deletions envelope.go
Original file line number Diff line number Diff line change
Expand Up @@ -203,15 +203,12 @@ func (r *envelopeReader) Unmarshal(message any) *Error {
// stream. Save the message for protocol-specific code to process and
// return a sentinel error. Since we've deferred functions to return env's
// underlying buffer to a pool, we need to keep a copy.
copiedData := make([]byte, data.Len())
copy(copiedData, data.Bytes())
r.last = envelope{
Data: r.bufferPool.Get(),
Data: bytes.NewBuffer(copiedData),
Flags: env.Flags,
}
// Don't return last to the pool! We're going to reference the data
// elsewhere.
if _, err := r.last.Data.ReadFrom(data); err != nil {
return errorf(CodeUnknown, "copy final envelope: %w", err)
}
return errSpecialEnvelope
}

Expand Down

0 comments on commit daa0efc

Please sign in to comment.