From 777341c3d0150b239276e888c25e23ea7cfa7b25 Mon Sep 17 00:00:00 2001 From: Urvang Joshi Date: Mon, 2 Jul 2012 10:17:43 +0530 Subject: [PATCH 1/2] Fix a memleak in WebPMuxCreate() Change-Id: I3658b5ae487082aef28989eb8abc274c207fef0f --- src/mux/muxread.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/mux/muxread.c b/src/mux/muxread.c index 2fd6d07b..10d46b21 100644 --- a/src/mux/muxread.c +++ b/src/mux/muxread.c @@ -85,6 +85,8 @@ WebPMux* WebPMuxCreateInternal(const WebPData* const bitstream, int copy_data, WebPMuxImage* wpi = NULL; const uint8_t* data; size_t size; + WebPChunk chunk; + ChunkInit(&chunk); // Sanity checks. 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. while (data != end) { WebPChunkId id; - WebPChunk chunk; WebPMuxError err; - ChunkInit(&chunk); err = ChunkAssignData(&chunk, data, size, riff_size, copy_data); 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 (ChunkSetNth(&chunk, chunk_list, 0) != WEBP_MUX_OK) goto Err; } - { const size_t data_size = ChunkDiskSize(&chunk); data += data_size; size -= data_size; } + ChunkInit(&chunk); } // Validate mux if complete. @@ -179,6 +179,7 @@ WebPMux* WebPMuxCreateInternal(const WebPData* const bitstream, int copy_data, return mux; // All OK; Err: // Something bad happened. + ChunkRelease(&chunk); MuxImageDelete(wpi); WebPMuxDelete(mux); return NULL; From 5d09a244b74952809ded1f30d0cbf15d6cd8be92 Mon Sep 17 00:00:00 2001 From: Urvang Joshi Date: Mon, 2 Jul 2012 11:17:24 +0530 Subject: [PATCH 2/2] WebPMuxCreate() error handling: Directly return NULL if no allocation is done yet. Change-Id: If39ab7f5a55833263d3372fa0a5d9b0a600cb9ed --- src/mux/muxread.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/mux/muxread.c b/src/mux/muxread.c index 10d46b21..b294c770 100644 --- a/src/mux/muxread.c +++ b/src/mux/muxread.c @@ -89,21 +89,21 @@ WebPMux* WebPMuxCreateInternal(const WebPData* const bitstream, int copy_data, ChunkInit(&chunk); // Sanity checks. - if (version != WEBP_MUX_ABI_VERSION) goto Err; // version mismatch - if (bitstream == NULL) goto Err; + if (version != WEBP_MUX_ABI_VERSION) return NULL; // version mismatch + if (bitstream == NULL) return NULL; data = bitstream->bytes_; size = bitstream->size_; - if (data == NULL) goto Err; + if (data == NULL) return NULL; if (size < RIFF_HEADER_SIZE) return NULL; if (GetLE32(data + 0) != mktag('R', 'I', 'F', 'F') || GetLE32(data + CHUNK_HEADER_SIZE) != mktag('W', 'E', 'B', 'P')) { - goto Err; + return NULL; } mux = WebPMuxNew(); - if (mux == NULL) goto Err; + if (mux == NULL) return NULL; if (size < RIFF_HEADER_SIZE + TAG_SIZE) goto Err;