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:
James Zern 2022-04-04 10:58:11 -07:00
parent 2d3293ad76
commit 89f774e61d
2 changed files with 6 additions and 4 deletions

View File

@ -70,6 +70,7 @@ void WebPMuxDelete(WebPMux* mux) {
err = ChunkAssignData(&chunk, data, copy_data, tag); \
if (err == WEBP_MUX_OK) { \
err = ChunkSetHead(&chunk, (LIST)); \
if (err != WEBP_MUX_OK) ChunkRelease(&chunk); \
} \
return err; \
}

View File

@ -155,17 +155,18 @@ WebPMuxError ChunkSetHead(WebPChunk* const chunk,
WebPMuxError ChunkAppend(WebPChunk* const chunk,
WebPChunk*** const chunk_list) {
WebPMuxError err;
assert(chunk_list != NULL && *chunk_list != NULL);
if (**chunk_list == NULL) {
ChunkSetHead(chunk, *chunk_list);
err = ChunkSetHead(chunk, *chunk_list);
} else {
WebPChunk* last_chunk = **chunk_list;
while (last_chunk->next_ != NULL) last_chunk = last_chunk->next_;
ChunkSetHead(chunk, &last_chunk->next_);
*chunk_list = &last_chunk->next_;
err = ChunkSetHead(chunk, &last_chunk->next_);
if (err == WEBP_MUX_OK) *chunk_list = &last_chunk->next_;
}
return WEBP_MUX_OK;
return err;
}
//------------------------------------------------------------------------------