From caedfada2addf611eebb8c88477a47c6c2f641ca Mon Sep 17 00:00:00 2001
From: Cristy <urban-warrior@imagemagick.org>
Date: Thu, 4 Jan 2018 06:49:08 -0500
Subject: [PATCH] https://github.com/ImageMagick/ImageMagick/issues/931

---
 coders/dcm.c | 12 ++++++++++++
 coders/rla.c |  7 +++++--
 2 files changed, 17 insertions(+), 2 deletions(-)

diff --git a/coders/dcm.c b/coders/dcm.c
index 94e8e6a8b..ca13d85fd 100644
--- a/coders/dcm.c
+++ b/coders/dcm.c
@@ -2979,6 +2979,14 @@ static Image *ReadDCMImage(const ImageInfo *image_info,ExceptionInfo *exception)
 { \
   if (data != (unsigned char *) NULL) \
     data=(unsigned char *) RelinquishMagickMemory(data); \
+  if (graymap != (int *) NULL) \
+    graymap=(int *) RelinquishMagickMemory(graymap); \
+  if (bluemap != (int *) NULL) \
+    bluemap=(int *) RelinquishMagickMemory(bluemap); \
+  if (greenmap != (int *) NULL) \
+    greenmap=(int *) RelinquishMagickMemory(greenmap); \
+  if (redmap != (int *) NULL) \
+    redmap=(int *) RelinquishMagickMemory(redmap); \
   if (stream_info != (DCMStreamInfo *) NULL) \
     stream_info=(DCMStreamInfo *) RelinquishMagickMemory(stream_info); \
   ThrowReaderException((exception),(message)); \
@@ -3064,6 +3072,10 @@ static Image *ReadDCMImage(const ImageInfo *image_info,ExceptionInfo *exception)
     Read DCM preamble.
   */
   data=(unsigned char *) NULL;
+  graymap=(int *) NULL;
+  redmap=(int *) NULL;
+  greenmap=(int *) NULL;
+  bluemap=(int *) NULL;
   stream_info=(DCMStreamInfo *) AcquireMagickMemory(sizeof(*stream_info));
   if (stream_info == (DCMStreamInfo *) NULL)
     ThrowDCMException(ResourceLimitError,"MemoryAllocationFailed");
diff --git a/coders/rla.c b/coders/rla.c
index 548fec314..b2cce34be 100644
--- a/coders/rla.c
+++ b/coders/rla.c
@@ -287,7 +287,10 @@ static Image *ReadRLAImage(const ImageInfo *image_info,ExceptionInfo *exception)
   {
     offset=SeekBlob(image,scanlines[image->rows-y-1],SEEK_SET);
     if (offset < 0)
-      ThrowReaderException(CorruptImageError,"ImproperImageHeader");
+      {
+        scanlines=(MagickOffsetType *) RelinquishMagickMemory(scanlines);
+        ThrowReaderException(CorruptImageError,"ImproperImageHeader");
+      }
     for (channel=0; channel < (int) rla_info.number_channels; channel++)
     {
       length=ReadBlobMSBSignedShort(image);
@@ -387,10 +390,10 @@ static Image *ReadRLAImage(const ImageInfo *image_info,ExceptionInfo *exception)
     if (status == MagickFalse)
       break;
   }
+  scanlines=(MagickOffsetType *) RelinquishMagickMemory(scanlines);
   if (EOFBlob(image) != MagickFalse)
     ThrowFileException(exception,CorruptImageError,"UnexpectedEndOfFile",
       image->filename);
-  scanlines=(MagickOffsetType *) RelinquishMagickMemory(scanlines);
   (void) CloseBlob(image);
   return(GetFirstImageInList(image));
 }
-- 
2.40.0