Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
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
6 changes: 4 additions & 2 deletions frame.go
Original file line number Diff line number Diff line change
Expand Up @@ -746,7 +746,8 @@ func (f *framer) setLength(length int) {
}

func (f *framer) finish() error {
if len(f.buf) > maxFrameSize {
bufLen := len(f.buf)
if bufLen > maxFrameSize {
// huge app frame, lets remove it so it doesn't bloat the heap
f.buf = make([]byte, defaultBufSize)
return ErrFrameTooBig
Expand All @@ -764,8 +765,9 @@ func (f *framer) finish() error {
}

f.buf = append(f.buf[:headSize], compressed...)
bufLen = len(f.buf)
}
length := len(f.buf) - headSize
length := bufLen - headSize
f.setLength(length)

return nil
Expand Down
5 changes: 3 additions & 2 deletions lz4/lz4.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,8 @@ func (s LZ4Compressor) Name() string {
}

func (s LZ4Compressor) Encode(data []byte) ([]byte, error) {
buf := make([]byte, lz4.CompressBlockBound(len(data)+4))
dataLen := len(data)
buf := make([]byte, lz4.CompressBlockBound(dataLen)+4)
var compressor lz4.Compressor
n, err := compressor.CompressBlock(data, buf[4:])
// According to lz4.CompressBlock doc, it doesn't fail as long as the dst
Expand All @@ -57,7 +58,7 @@ func (s LZ4Compressor) Encode(data []byte) ([]byte, error) {
if err != nil {
return nil, err
}
binary.BigEndian.PutUint32(buf, uint32(len(data)))
binary.BigEndian.PutUint32(buf, uint32(dataLen))
return buf[:n+4], nil
}

Expand Down