diff --git a/src/mux/muxi.h b/src/mux/muxi.h index 0320f811..c1c86d3a 100644 --- a/src/mux/muxi.h +++ b/src/mux/muxi.h @@ -174,7 +174,8 @@ uint8_t* ChunkListEmit(const WebPChunk* chunk_list, uint8_t* dst); // Initialize. void MuxImageInit(WebPMuxImage* const wpi); -// Delete image 'wpi'. +// Delete image 'wpi' and return the next image in the list or NULL. +// 'wpi' can be NULL. WebPMuxImage* MuxImageDelete(WebPMuxImage* const wpi); // Delete all images in 'wpi_list'. diff --git a/src/mux/muxinternal.c b/src/mux/muxinternal.c index 99e37b26..8795cd17 100644 --- a/src/mux/muxinternal.c +++ b/src/mux/muxinternal.c @@ -345,6 +345,7 @@ WebPMuxError MuxImageSetNth(const WebPMuxImage* wpi, WebPMuxImage** wpi_list, // MuxImage deletion methods. WebPMuxImage* MuxImageDelete(WebPMuxImage* const wpi) { + // Delete the components of wpi. If wpi is NULL this is a noop. WebPMuxImage* const next = MuxImageRelease(wpi); free(wpi); return next; diff --git a/src/mux/muxread.c b/src/mux/muxread.c index 7b8c622e..31b85cb1 100644 --- a/src/mux/muxread.c +++ b/src/mux/muxread.c @@ -125,6 +125,7 @@ WebPMux* WebPMuxCreate(const uint8_t* data, uint32_t size, int copy_data, size -= RIFF_HEADER_SIZE; wpi = (WebPMuxImage*)malloc(sizeof(*wpi)); + if (wpi == NULL) goto Err; MuxImageInit(wpi); // Loop over chunks.