mirror of
https://github.com/webmproject/libwebp.git
synced 2025-04-24 17:56:46 +02:00
mux{edit,internal}: fix leaks on error
several calls to ChunkSetHead() were unchecked, causing the chunk to leak should the call fail due to OOM Tested: for i in `seq 1 1125`; do export MALLOC_FAIL_AT=$i ./examples/gif2webp gif_file ./examples/gif2webp -mixed gif_file done for i in `seq 1 171`; do export MALLOC_FAIL_AT=$i ./examples/img2webp jpeg_file -o /dev/null ./examples/img2webp -mixed jpeg_file -o /dev/null done Change-Id: I479bc487f61b493e5ce033872d353007055c172a
This commit is contained in:
parent
2d3293ad76
commit
89f774e61d
@ -70,6 +70,7 @@ void WebPMuxDelete(WebPMux* mux) {
|
|||||||
err = ChunkAssignData(&chunk, data, copy_data, tag); \
|
err = ChunkAssignData(&chunk, data, copy_data, tag); \
|
||||||
if (err == WEBP_MUX_OK) { \
|
if (err == WEBP_MUX_OK) { \
|
||||||
err = ChunkSetHead(&chunk, (LIST)); \
|
err = ChunkSetHead(&chunk, (LIST)); \
|
||||||
|
if (err != WEBP_MUX_OK) ChunkRelease(&chunk); \
|
||||||
} \
|
} \
|
||||||
return err; \
|
return err; \
|
||||||
}
|
}
|
||||||
|
@ -155,17 +155,18 @@ WebPMuxError ChunkSetHead(WebPChunk* const chunk,
|
|||||||
|
|
||||||
WebPMuxError ChunkAppend(WebPChunk* const chunk,
|
WebPMuxError ChunkAppend(WebPChunk* const chunk,
|
||||||
WebPChunk*** const chunk_list) {
|
WebPChunk*** const chunk_list) {
|
||||||
|
WebPMuxError err;
|
||||||
assert(chunk_list != NULL && *chunk_list != NULL);
|
assert(chunk_list != NULL && *chunk_list != NULL);
|
||||||
|
|
||||||
if (**chunk_list == NULL) {
|
if (**chunk_list == NULL) {
|
||||||
ChunkSetHead(chunk, *chunk_list);
|
err = ChunkSetHead(chunk, *chunk_list);
|
||||||
} else {
|
} else {
|
||||||
WebPChunk* last_chunk = **chunk_list;
|
WebPChunk* last_chunk = **chunk_list;
|
||||||
while (last_chunk->next_ != NULL) last_chunk = last_chunk->next_;
|
while (last_chunk->next_ != NULL) last_chunk = last_chunk->next_;
|
||||||
ChunkSetHead(chunk, &last_chunk->next_);
|
err = ChunkSetHead(chunk, &last_chunk->next_);
|
||||||
*chunk_list = &last_chunk->next_;
|
if (err == WEBP_MUX_OK) *chunk_list = &last_chunk->next_;
|
||||||
}
|
}
|
||||||
return WEBP_MUX_OK;
|
return err;
|
||||||
}
|
}
|
||||||
|
|
||||||
//------------------------------------------------------------------------------
|
//------------------------------------------------------------------------------
|
||||||
|
Loading…
x
Reference in New Issue
Block a user