From: root <356986351@qq.com> Date: Fri, 15 Sep 2017 16:13:56 +0000 (+0000) Subject: fix memory leak in miff X-Git-Tag: 7.0.7-3~21 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=0e298bade27dd8bd6f1569d13b9a8e2fd9e6b53c;p=imagemagick fix memory leak in miff --- diff --git a/coders/miff.c b/coders/miff.c index 7e019a00a..d77a07cdd 100644 --- a/coders/miff.c +++ b/coders/miff.c @@ -1188,6 +1188,7 @@ static Image *ReadMIFFImage(const ImageInfo *image_info, switch (image->depth) { default: + colormap=(unsigned char *) RelinquishMagickMemory(colormap); ThrowReaderException(CorruptImageError, "ImageDepthNotSupported"); case 8: @@ -1258,7 +1259,10 @@ static Image *ReadMIFFImage(const ImageInfo *image_info, { status=SetQuantumFormat(image,quantum_info,quantum_format); if (status == MagickFalse) - ThrowReaderException(ResourceLimitError,"MemoryAllocationFailed"); + { + quantum_info=DestroyQuantumInfo(quantum_info); + ThrowReaderException(ResourceLimitError,"MemoryAllocationFailed"); + } } packet_size=(size_t) (quantum_info->depth/8); if (image->storage_class == DirectClass) @@ -1277,7 +1281,10 @@ static Image *ReadMIFFImage(const ImageInfo *image_info, compress_pixels=(unsigned char *) AcquireQuantumMemory(compress_extent, sizeof(*compress_pixels)); if (compress_pixels == (unsigned char *) NULL) - ThrowReaderException(ResourceLimitError,"MemoryAllocationFailed"); + { + quantum_info=DestroyQuantumInfo(quantum_info); + ThrowReaderException(ResourceLimitError,"MemoryAllocationFailed"); + } /* Read image pixels. */ @@ -1404,6 +1411,8 @@ static Image *ReadMIFFImage(const ImageInfo *image_info, if (length > compress_extent) { (void) BZ2_bzDecompressEnd(&bzip_info); + quantum_info=DestroyQuantumInfo(quantum_info); + compress_pixels=(unsigned char *) RelinquishMagickMemory(compress_pixels); ThrowReaderException(CorruptImageError, "UnableToReadImageData"); } @@ -1441,6 +1450,8 @@ static Image *ReadMIFFImage(const ImageInfo *image_info, if (length > compress_extent) { lzma_end(&lzma_info); + quantum_info=DestroyQuantumInfo(quantum_info); + compress_pixels=(unsigned char *) RelinquishMagickMemory(compress_pixels); ThrowReaderException(CorruptImageError, "UnableToReadImageData"); } @@ -1481,6 +1492,8 @@ static Image *ReadMIFFImage(const ImageInfo *image_info, if (length > compress_extent) { (void) inflateEnd(&zip_info); + quantum_info=DestroyQuantumInfo(quantum_info); + compress_pixels=(unsigned char *) RelinquishMagickMemory(compress_pixels); ThrowReaderException(CorruptImageError, "UnableToReadImageData"); } @@ -1555,7 +1568,11 @@ static Image *ReadMIFFImage(const ImageInfo *image_info, offset=SeekBlob(image,-((MagickOffsetType) bzip_info.avail_in),SEEK_CUR); if (offset < 0) - ThrowReaderException(CorruptImageError,"ImproperImageHeader"); + { + quantum_info=DestroyQuantumInfo(quantum_info); + compress_pixels=(unsigned char *) RelinquishMagickMemory(compress_pixels); + ThrowReaderException(CorruptImageError,"ImproperImageHeader"); + } } code=BZ2_bzDecompressEnd(&bzip_info); if (code != BZ_OK) @@ -1591,7 +1608,11 @@ static Image *ReadMIFFImage(const ImageInfo *image_info, offset=SeekBlob(image,-((MagickOffsetType) zip_info.avail_in), SEEK_CUR); if (offset < 0) - ThrowReaderException(CorruptImageError,"ImproperImageHeader"); + { + quantum_info=DestroyQuantumInfo(quantum_info); + compress_pixels=(unsigned char *) RelinquishMagickMemory(compress_pixels); + ThrowReaderException(CorruptImageError,"ImproperImageHeader"); + } } code=inflateEnd(&zip_info); if (code != LZMA_OK)