Fix a memleak in WebPMuxCreate()

Change-Id: I3658b5ae487082aef28989eb8abc274c207fef0f
This commit is contained in:
Urvang Joshi 2012-07-02 10:17:43 +05:30
parent 4c3975792b
commit 777341c3d0

View File

@ -85,6 +85,8 @@ WebPMux* WebPMuxCreateInternal(const WebPData* const bitstream, int copy_data,
WebPMuxImage* wpi = NULL; WebPMuxImage* wpi = NULL;
const uint8_t* data; const uint8_t* data;
size_t size; size_t size;
WebPChunk chunk;
ChunkInit(&chunk);
// Sanity checks. // Sanity checks.
if (version != WEBP_MUX_ABI_VERSION) goto Err; // version mismatch if (version != WEBP_MUX_ABI_VERSION) goto Err; // version mismatch
@ -132,10 +134,8 @@ WebPMux* WebPMuxCreateInternal(const WebPData* const bitstream, int copy_data,
// Loop over chunks. // Loop over chunks.
while (data != end) { while (data != end) {
WebPChunkId id; WebPChunkId id;
WebPChunk chunk;
WebPMuxError err; WebPMuxError err;
ChunkInit(&chunk);
err = ChunkAssignData(&chunk, data, size, riff_size, copy_data); err = ChunkAssignData(&chunk, data, size, riff_size, copy_data);
if (err != WEBP_MUX_OK) goto Err; if (err != WEBP_MUX_OK) goto Err;
@ -164,12 +164,12 @@ WebPMux* WebPMuxCreateInternal(const WebPData* const bitstream, int copy_data,
if (chunk_list == NULL) chunk_list = &mux->unknown_; if (chunk_list == NULL) chunk_list = &mux->unknown_;
if (ChunkSetNth(&chunk, chunk_list, 0) != WEBP_MUX_OK) goto Err; if (ChunkSetNth(&chunk, chunk_list, 0) != WEBP_MUX_OK) goto Err;
} }
{ {
const size_t data_size = ChunkDiskSize(&chunk); const size_t data_size = ChunkDiskSize(&chunk);
data += data_size; data += data_size;
size -= data_size; size -= data_size;
} }
ChunkInit(&chunk);
} }
// Validate mux if complete. // Validate mux if complete.
@ -179,6 +179,7 @@ WebPMux* WebPMuxCreateInternal(const WebPData* const bitstream, int copy_data,
return mux; // All OK; return mux; // All OK;
Err: // Something bad happened. Err: // Something bad happened.
ChunkRelease(&chunk);
MuxImageDelete(wpi); MuxImageDelete(wpi);
WebPMuxDelete(mux); WebPMuxDelete(mux);
return NULL; return NULL;