From c901886efecdd8acc8435dfac70cfbec52bd3586 Mon Sep 17 00:00:00 2001 From: root <356986351@qq.com> Date: Fri, 15 Sep 2017 16:31:45 +0000 Subject: [PATCH] fix memory leak in map --- coders/map.c | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/coders/map.c b/coders/map.c index 374ccfb14..558bb90ad 100644 --- a/coders/map.c +++ b/coders/map.c @@ -169,13 +169,21 @@ static Image *ReadMAPImage(const ImageInfo *image_info,ExceptionInfo *exception) sizeof(*colormap)); if ((pixels == (unsigned char *) NULL) || (colormap == (unsigned char *) NULL)) - ThrowReaderException(ResourceLimitError,"MemoryAllocationFailed"); + { + pixels=(unsigned char *) RelinquishMagickMemory(pixels); + colormap=(unsigned char *) RelinquishMagickMemory(colormap); + ThrowReaderException(ResourceLimitError,"MemoryAllocationFailed"); + } /* Read image colormap. */ count=ReadBlob(image,packet_size*image->colors,colormap); if (count != (ssize_t) (packet_size*image->colors)) - ThrowReaderException(CorruptImageError,"InsufficientImageDataInFile"); + { + pixels=(unsigned char *) RelinquishMagickMemory(pixels); + colormap=(unsigned char *) RelinquishMagickMemory(colormap); + ThrowReaderException(CorruptImageError,"InsufficientImageDataInFile"); + } p=colormap; if (image->depth <= 8) for (i=0; i < (ssize_t) image->colors; i++) @@ -201,11 +209,15 @@ static Image *ReadMAPImage(const ImageInfo *image_info,ExceptionInfo *exception) if (image_info->ping != MagickFalse) { (void) CloseBlob(image); + pixels=(unsigned char *) RelinquishMagickMemory(pixels); return(GetFirstImageInList(image)); } status=SetImageExtent(image,image->columns,image->rows,exception); if (status == MagickFalse) - return(DestroyImageList(image)); + { + pixels=(unsigned char *) RelinquishMagickMemory(pixels); + return(DestroyImageList(image)); + } /* Read image pixels. */ -- 2.40.0