mirror of
https://github.com/talgo-cloud/talgo-libwebp.git
synced 2026-03-07 21:48:16 -08:00
Fix memory leak in animation encoding (#1)
We were never freeing the buffer that holds the assembled WebP animation. Instead, copy the buffer into Go and free it right after assembly.
This commit is contained in:
parent
6042ce446e
commit
1fabc3b466
1 changed files with 15 additions and 4 deletions
|
|
@ -107,15 +107,26 @@ func (ae *AnimationEncoder) Assemble() ([]byte, error) {
|
|||
|
||||
data := &C.WebPData{}
|
||||
C.WebPDataInit(data)
|
||||
defer C.WebPDataClear(data)
|
||||
|
||||
if C.WebPAnimEncoderAssemble(ae.c, data) == 0 {
|
||||
return nil, errors.New("Error assembling animation")
|
||||
}
|
||||
|
||||
return C.GoBytes(
|
||||
size := int(data.size)
|
||||
out := make([]byte, size)
|
||||
n := copy(
|
||||
out, C.GoBytes(
|
||||
unsafe.Pointer(data.bytes),
|
||||
C.int(int(data.size)),
|
||||
), nil
|
||||
C.int(size),
|
||||
),
|
||||
)
|
||||
|
||||
if n != size {
|
||||
return nil, errors.New("Error copying animation from C to Go")
|
||||
}
|
||||
|
||||
return out, nil
|
||||
}
|
||||
|
||||
// Close deletes the encoder and frees resources.
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue