]> granicus.if.org Git - imagemagick/commitdiff
Fixed memory leak reported in #459.
authorDirk Lemstra <dirk@git.imagemagick.org>
Tue, 2 May 2017 06:42:22 +0000 (08:42 +0200)
committerDirk Lemstra <dirk@git.imagemagick.org>
Tue, 2 May 2017 06:42:22 +0000 (08:42 +0200)
coders/palm.c

index 2905f43031474cfa3fe056f0064041925d718713..66fde84d346a09b14c996826b467289e10344a24 100644 (file)
@@ -477,7 +477,12 @@ static Image *ReadPALMImage(const ImageInfo *image_info,
       if (bits_per_pixel == 16)
         {
           if (image->columns > (2*bytes_per_row))
-            ThrowReaderException(CorruptImageError,"CorruptImage");
+            {
+              one_row=(unsigned char *) RelinquishMagickMemory(one_row);
+              if (compressionType == PALM_COMPRESSION_SCANLINE)
+                lastrow=(unsigned char *) RelinquishMagickMemory(lastrow);
+              ThrowReaderException(CorruptImageError,"CorruptImage");
+            }
           for (x=0; x < (ssize_t) image->columns; x++)
           {
             color16=(*ptr++ << 8);
@@ -498,7 +503,12 @@ static Image *ReadPALMImage(const ImageInfo *image_info,
           for (x=0; x < (ssize_t) image->columns; x++)
           {
             if ((size_t) (ptr-one_row) >= bytes_per_row)
-              ThrowReaderException(CorruptImageError,"CorruptImage");
+              {
+                one_row=(unsigned char *) RelinquishMagickMemory(one_row);
+                if (compressionType == PALM_COMPRESSION_SCANLINE)
+                  lastrow=(unsigned char *) RelinquishMagickMemory(lastrow);
+                ThrowReaderException(CorruptImageError,"CorruptImage");
+              }
             index=(Quantum) (mask-(((*ptr) & (mask << bit)) >> bit));
             SetPixelIndex(image,index,q);
             SetPixelViaPixelInfo(image,image->colormap+(ssize_t) index,q);