From e812d4b0eedb940dcdab3f73dfa04c6b21cc1000 Mon Sep 17 00:00:00 2001 From: Dirk Lemstra Date: Sun, 7 May 2017 12:12:24 +0200 Subject: [PATCH] Fixed various memory leaks reported in #475. --- coders/png.c | 22 +++++++++++++++++----- 1 file changed, 17 insertions(+), 5 deletions(-) diff --git a/coders/png.c b/coders/png.c index cbe6bdd3d..d212497dd 100644 --- a/coders/png.c +++ b/coders/png.c @@ -4701,7 +4701,10 @@ static Image *ReadOneJNGImage(MngInfo *mng_info, exception); if (status == MagickFalse) - return(DestroyImageList(image)); + { + color_image=DestroyImage(color_image); + return(DestroyImageList(image)); + } if ((image_info->ping == MagickFalse) && (jng_color_type >= 12)) { @@ -4709,15 +4712,19 @@ static Image *ReadOneJNGImage(MngInfo *mng_info, AcquireMagickMemory(sizeof(ImageInfo)); if (alpha_image_info == (ImageInfo *) NULL) - ThrowReaderException(ResourceLimitError, - "MemoryAllocationFailed"); + { + color_image=DestroyImage(color_image); + ThrowReaderException(ResourceLimitError, + "MemoryAllocationFailed"); + } GetImageInfo(alpha_image_info); alpha_image=AcquireImage(alpha_image_info,exception); if (alpha_image == (Image *) NULL) { - alpha_image=DestroyImage(alpha_image); + alpha_image_info=DestroyImageInfo(alpha_image_info); + color_image=DestroyImage(color_image); ThrowReaderException(ResourceLimitError, "MemoryAllocationFailed"); } @@ -4731,7 +4738,12 @@ static Image *ReadOneJNGImage(MngInfo *mng_info, exception); if (status == MagickFalse) - return(DestroyImageList(image)); + { + alpha_image=DestroyImage(alpha_image); + alpha_image_info=DestroyImageInfo(alpha_image_info); + color_image=DestroyImage(color_image); + return(DestroyImageList(image)); + } if (jng_alpha_compression_method == 0) { -- 2.40.0