File ImageMagick-CVE-2017-18251.patch of Package ImageMagick.8212

Index: ImageMagick-6.8.8-1/coders/pcd.c
===================================================================
--- ImageMagick-6.8.8-1.orig/coders/pcd.c	2018-04-06 11:05:53.784244033 +0200
+++ ImageMagick-6.8.8-1/coders/pcd.c	2018-04-06 11:05:55.260269815 +0200
@@ -604,7 +604,15 @@ static Image *ReadPCDImage(const ImageIn
     sizeof(*luma));
   if ((chroma1 == (unsigned char *) NULL) ||
       (chroma2 == (unsigned char *) NULL) || (luma == (unsigned char *) NULL))
-    ThrowReaderException(ResourceLimitError,"MemoryAllocationFailed");
+    {
+      if (chroma1 != (unsigned char *) NULL)
+        chroma1=(unsigned char *) RelinquishMagickMemory(chroma1);
+      if (chroma2 != (unsigned char *) NULL)
+        chroma2=(unsigned char *) RelinquishMagickMemory(chroma2);
+      if (luma != (unsigned char *) NULL)
+        luma=(unsigned char *) RelinquishMagickMemory(luma);
+      ThrowReaderException(ResourceLimitError,"MemoryAllocationFailed");
+    }
   /*
     Advance to image data.
   */