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

Index: ImageMagick-6.8.8-1/coders/msl.c
===================================================================
--- ImageMagick-6.8.8-1.orig/coders/msl.c	2018-02-16 15:10:04.402181713 +0100
+++ ImageMagick-6.8.8-1/coders/msl.c	2018-02-16 15:12:09.276408501 +0100
@@ -610,11 +610,11 @@ static void MSLStartElement(void *contex
     channel;
 
   char
+    *attribute,
     key[MaxTextExtent],
     *value;
 
   const char
-    *attribute,
     *keyword;
 
   double
@@ -698,6 +698,7 @@ static void MSLStartElement(void *contex
               attribute=InterpretImageProperties(msl_info->image_info[n],
                 msl_info->attributes[n],(const char *) attributes[i]);
               CloneString(&value,attribute);
+              attribute=DestroyString(attribute);
               switch (*keyword)
               {
                 case 'C':
@@ -775,6 +776,7 @@ static void MSLStartElement(void *contex
               attribute=InterpretImageProperties(msl_info->image_info[n],
                 msl_info->attributes[n],(const char *) attributes[i]);
               CloneString(&value,attribute);
+              attribute=DestroyString(attribute);
               switch (*keyword)
               {
                 case 'A':
@@ -1106,6 +1108,7 @@ static void MSLStartElement(void *contex
               attribute=InterpretImageProperties(msl_info->image_info[n],
                 msl_info->attributes[n],(const char *) attributes[i]);
               CloneString(&value,attribute);
+              attribute=DestroyString(attribute);
               switch (*keyword)
               {
                 case 'S':
@@ -1168,6 +1171,7 @@ static void MSLStartElement(void *contex
               attribute=InterpretImageProperties(msl_info->image_info[n],
                 msl_info->attributes[n],(const char *) attributes[i]);
               CloneString(&value,attribute);
+              attribute=DestroyString(attribute);
               switch (*keyword)
               {
                 case 'C':
@@ -1263,6 +1267,7 @@ static void MSLStartElement(void *contex
               attribute=InterpretImageProperties(msl_info->image_info[n],
                 msl_info->attributes[n],(const char *) attributes[i]);
               CloneString(&value,attribute);
+              attribute=DestroyString(attribute);
               switch (*keyword)
               {
                 case 'C':
@@ -1384,6 +1389,7 @@ static void MSLStartElement(void *contex
               attribute=InterpretImageProperties(msl_info->image_info[n],
                 msl_info->attributes[n],(const char *) attributes[i]);
               CloneString(&value,attribute);
+              attribute=DestroyString(attribute);
               switch (*keyword)
               {
                 case 'F':
@@ -1445,9 +1451,11 @@ static void MSLStartElement(void *contex
         {
           for (i=0; (attributes[i] != (const xmlChar *) NULL); i++)
           {
-          keyword=(const char *) attributes[i++];
-          CloneString(&value,InterpretImageProperties(msl_info->image_info[n],
-            msl_info->attributes[n],(const char *) attributes[i]));
+            keyword=(const char *) attributes[i++];
+            attribute=InterpretImageProperties(msl_info->image_info[n],
+              msl_info->attributes[n],(const char *) attributes[i]);
+            CloneString(&value,attribute);
+            attribute=DestroyString(attribute);
           switch (*keyword)
           {
             case 'R':
@@ -1519,6 +1527,7 @@ static void MSLStartElement(void *contex
               attribute=InterpretImageProperties(msl_info->image_info[n],
                 msl_info->attributes[n],(const char *) attributes[i]);
               CloneString(&value,attribute);
+              attribute=DestroyString(attribute);
               switch (*keyword)
               {
                 case 'G':
@@ -1628,6 +1637,7 @@ static void MSLStartElement(void *contex
               attribute=InterpretImageProperties(msl_info->image_info[n],
                 msl_info->attributes[n],(const char *) attributes[i]);
               CloneString(&value,attribute);
+              attribute=DestroyString(attribute);
               switch (*keyword)
               {
                 case 'B':
@@ -1756,6 +1766,7 @@ static void MSLStartElement(void *contex
               attribute=InterpretImageProperties(msl_info->image_info[n],
                 msl_info->attributes[n],(const char *) attributes[i]);
               CloneString(&value,attribute);
+              attribute=DestroyString(attribute);
               switch (*keyword)
               {
                 case 'C':
@@ -1808,6 +1819,7 @@ static void MSLStartElement(void *contex
               attribute=InterpretImageProperties(msl_info->image_info[n],
                 msl_info->attributes[n],(const char *) attributes[i]);
               CloneString(&value,attribute);
+              attribute=DestroyString(attribute);
               switch (*keyword)
               {
                 case 'B':
@@ -2095,6 +2107,7 @@ static void MSLStartElement(void *contex
               attribute=InterpretImageProperties(msl_info->image_info[n],
                 msl_info->attributes[n],(const char *) attributes[i]);
               CloneString(&value,attribute);
+              attribute=DestroyString(attribute);
               switch (*keyword)
               {
                 case 'S':
@@ -2147,6 +2160,7 @@ static void MSLStartElement(void *contex
               attribute=InterpretImageProperties(msl_info->image_info[n],
                 msl_info->attributes[n],(const char *) attributes[i]);
               CloneString(&value,attribute);
+              attribute=DestroyString(attribute);
               switch (*keyword)
               {
                 case 'G':
@@ -2248,6 +2262,7 @@ static void MSLStartElement(void *contex
               attribute=InterpretImageProperties(msl_info->image_info[n],
                 msl_info->attributes[n],(const char *) attributes[i]);
               CloneString(&value,attribute);
+              attribute=DestroyString(attribute);
               switch (*keyword)
               {
                 case 'D':
@@ -2299,6 +2314,7 @@ static void MSLStartElement(void *contex
               attribute=InterpretImageProperties(msl_info->image_info[n],
                 msl_info->attributes[n],(const char *) attributes[i]);
               CloneString(&value,attribute);
+              attribute=DestroyString(attribute);
               ThrowMSLException(OptionError,"UnrecognizedAttribute",keyword);
             }
           despeckle_image=DespeckleImage(msl_info->image[n],
@@ -2324,6 +2340,7 @@ static void MSLStartElement(void *contex
               attribute=InterpretImageProperties(msl_info->image_info[n],
                 msl_info->attributes[n],(const char *) attributes[i]);
               CloneString(&value,attribute);
+              attribute=DestroyString(attribute);
               switch (*keyword)
               {
                 default:
@@ -2363,6 +2380,7 @@ static void MSLStartElement(void *contex
               attribute=InterpretImageProperties(msl_info->image_info[n],
                 msl_info->attributes[n],(const char *) attributes[i]);
               CloneString(&value,attribute);
+              attribute=DestroyString(attribute);
               switch (*keyword)
               {
                 case 'A':
@@ -2717,6 +2735,7 @@ static void MSLStartElement(void *contex
               attribute=InterpretImageProperties(msl_info->image_info[n],
                 msl_info->attributes[n],(const char *) attributes[i]);
               CloneString(&value,attribute);
+              attribute=DestroyString(attribute);
               switch (*keyword)
               {
                 case 'G':
@@ -2783,6 +2802,7 @@ static void MSLStartElement(void *contex
               attribute=InterpretImageProperties(msl_info->image_info[n],
                 msl_info->attributes[n],(const char *) attributes[i]);
               CloneString(&value,attribute);
+              attribute=DestroyString(attribute);
               switch (*keyword)
               {
                 case 'G':
@@ -2861,6 +2881,7 @@ static void MSLStartElement(void *contex
               attribute=InterpretImageProperties(msl_info->image_info[n],
                 msl_info->attributes[n],(const char *) attributes[i]);
               CloneString(&value,attribute);
+              attribute=DestroyString(attribute);
               ThrowMSLException(OptionError,"UnrecognizedAttribute",keyword);
             }
           enhance_image=EnhanceImage(msl_info->image[n],
@@ -2889,6 +2910,7 @@ static void MSLStartElement(void *contex
               attribute=InterpretImageProperties(msl_info->image_info[n],
                 msl_info->attributes[n],(const char *) attributes[i]);
               CloneString(&value,attribute);
+              attribute=DestroyString(attribute);
               switch (*keyword)
               {
                 default:
@@ -2953,6 +2975,7 @@ static void MSLStartElement(void *contex
               attribute=InterpretImageProperties(msl_info->image_info[n],
                 msl_info->attributes[n],(const char *) attributes[i]);
               CloneString(&value,attribute);
+              attribute=DestroyString(attribute);
               ThrowMSLException(OptionError,"UnrecognizedAttribute",keyword);
             }
           flip_image=FlipImage(msl_info->image[n],
@@ -2984,6 +3007,7 @@ static void MSLStartElement(void *contex
               attribute=InterpretImageProperties(msl_info->image_info[n],
                 msl_info->attributes[n],(const char *) attributes[i]);
               CloneString(&value,attribute);
+              attribute=DestroyString(attribute);
               ThrowMSLException(OptionError,"UnrecognizedAttribute",keyword);
             }
           flop_image=FlopImage(msl_info->image[n],
@@ -3019,6 +3043,7 @@ static void MSLStartElement(void *contex
               attribute=InterpretImageProperties(msl_info->image_info[n],
                 msl_info->attributes[n],(const char *) attributes[i]);
               CloneString(&value,attribute);
+              attribute=DestroyString(attribute);
               switch (*keyword)
               {
                 case 'C':
@@ -3172,6 +3197,7 @@ static void MSLStartElement(void *contex
               attribute=InterpretImageProperties(msl_info->image_info[n],
                 msl_info->attributes[n],(const char *) attributes[i]);
               CloneString(&value,attribute);
+              attribute=DestroyString(attribute);
               switch (*keyword)
               {
                 case 'B':
@@ -3340,8 +3366,10 @@ static void MSLStartElement(void *contex
           for (i=0; (attributes[i] != (const xmlChar *) NULL); i++)
           {
             keyword=(const char *) attributes[i++];
-            CloneString(&value,InterpretImageProperties(msl_info->image_info[n],
-              msl_info->attributes[n],(const char *) attributes[i]));
+            attribute=InterpretImageProperties(msl_info->image_info[n],
+              msl_info->attributes[n],(const char *) attributes[i]);
+            CloneString(&value,attribute);
+            attribute=DestroyString(attribute);
             switch (*keyword)
             {
               case 'C':
@@ -3411,6 +3439,7 @@ static void MSLStartElement(void *contex
               attribute=InterpretImageProperties(msl_info->image_info[n],
                 msl_info->attributes[n],(const char *) attributes[i]);
               CloneString(&value,attribute);
+              attribute=DestroyString(attribute);
               switch (*keyword)
               {
                 case 'A':
@@ -3558,6 +3587,7 @@ static void MSLStartElement(void *contex
               attribute=InterpretImageProperties(msl_info->image_info[n],
                 msl_info->attributes[n],(const char *) attributes[i]);
               CloneString(&value,attribute);
+              attribute=DestroyString(attribute);
               ThrowMSLException(OptionError,"UnrecognizedAttribute",keyword);
             }
           magnify_image=MagnifyImage(msl_info->image[n],
@@ -3597,6 +3627,7 @@ static void MSLStartElement(void *contex
               attribute=InterpretImageProperties(msl_info->image_info[n],
                 msl_info->attributes[n],(const char *) attributes[i]);
               CloneString(&value,attribute);
+              attribute=DestroyString(attribute);
               switch (*keyword)
               {
                 case 'D':
@@ -3682,6 +3713,7 @@ static void MSLStartElement(void *contex
               attribute=InterpretImageProperties(msl_info->image_info[n],
                 msl_info->attributes[n],(const char *) attributes[i]);
               CloneString(&value,attribute);
+              attribute=DestroyString(attribute);
               switch (*keyword)
               {
                 case 'B':
@@ -3805,6 +3837,7 @@ static void MSLStartElement(void *contex
               attribute=InterpretImageProperties(msl_info->image_info[n],
                 msl_info->attributes[n],(const char *) attributes[i]);
               CloneString(&value,attribute);
+              attribute=DestroyString(attribute);
               switch (*keyword)
               {
                 case 'G':
@@ -3872,6 +3905,7 @@ static void MSLStartElement(void *contex
               attribute=InterpretImageProperties(msl_info->image_info[n],
                 msl_info->attributes[n],(const char *) attributes[i]);
               CloneString(&value,attribute);
+              attribute=DestroyString(attribute);
               ThrowMSLException(OptionError,"UnrecognizedAttribute",keyword);
             }
           minify_image=MinifyImage(msl_info->image[n],
@@ -3908,6 +3942,7 @@ static void MSLStartElement(void *contex
               attribute=InterpretImageProperties(msl_info->image_info[n],
                 msl_info->attributes[n],(const char *) attributes[i]);
               CloneString(&value,attribute);
+              attribute=DestroyString(attribute);
               switch (*keyword)
               {
                 case 'B':
@@ -4033,6 +4068,7 @@ static void MSLStartElement(void *contex
               attribute=InterpretImageProperties(msl_info->image_info[n],
                 msl_info->attributes[n],(const char *) attributes[i]);
               CloneString(&value,attribute);
+              attribute=DestroyString(attribute);
               switch (*keyword)
               {
                 case 'C':
@@ -4097,6 +4133,7 @@ static void MSLStartElement(void *contex
               attribute=InterpretImageProperties(msl_info->image_info[n],
                 msl_info->attributes[n],(const char *) attributes[i]);
               CloneString(&value,attribute);
+              attribute=DestroyString(attribute);
               switch (*keyword)
               {
                 case 'C':
@@ -4152,6 +4189,7 @@ static void MSLStartElement(void *contex
               attribute=InterpretImageProperties(msl_info->image_info[n],
                 msl_info->attributes[n],(const char *) attributes[i]);
               CloneString(&value,attribute);
+              attribute=DestroyString(attribute);
               switch (*keyword)
               {
                 case 'G':
@@ -4221,6 +4259,7 @@ static void MSLStartElement(void *contex
               attribute=InterpretImageProperties(msl_info->image_info[n],
                 msl_info->attributes[n],(const char *) attributes[i]);
               CloneString(&value,attribute);
+              attribute=DestroyString(attribute);
               switch (*keyword)
               {
                 case 'C':
@@ -4284,6 +4323,7 @@ static void MSLStartElement(void *contex
             attribute=InterpretImageProperties(msl_info->image_info[n],
               msl_info->attributes[n],(const char *) attributes[i]);
             CloneString(&value,attribute);
+            attribute=DestroyString(attribute);
             switch (*keyword)
             {
               case 'O':
@@ -4334,6 +4374,7 @@ static void MSLStartElement(void *contex
               attribute=InterpretImageProperties(msl_info->image_info[n],
                 msl_info->attributes[n],(const char *) attributes[i]);
               CloneString(&value,attribute);
+              attribute=DestroyString(attribute);
               if (*keyword == '!')
                 {
                   /*
@@ -4434,6 +4475,7 @@ static void MSLStartElement(void *contex
               attribute=InterpretImageProperties(msl_info->image_info[n],
                 msl_info->attributes[n],(const char *) attributes[i]);
               CloneString(&value,attribute);
+              attribute=DestroyString(attribute);
               switch (*keyword)
               {
                 case 'C':
@@ -4541,6 +4583,7 @@ static void MSLStartElement(void *contex
               attribute=InterpretImageProperties(msl_info->image_info[n],
                 msl_info->attributes[n],(const char *) attributes[i]);
               CloneString(&value,attribute);
+              attribute=DestroyString(attribute);
               switch (*keyword)
               {
                 case 'A':
@@ -4910,6 +4953,7 @@ static void MSLStartElement(void *contex
               attribute=InterpretImageProperties(msl_info->image_info[n],
                 msl_info->attributes[n],(const char *) attributes[i]);
               CloneString(&value,attribute);
+              attribute=DestroyString(attribute);
               switch (*keyword)
               {
                 case 'G':
@@ -4986,8 +5030,10 @@ static void MSLStartElement(void *contex
           for (i=0; (attributes[i] != (const xmlChar *) NULL); i++)
           {
             keyword=(const char *) attributes[i++];
-            CloneString(&value,InterpretImageProperties(msl_info->image_info[n],
-              msl_info->attributes[n],(const char *) attributes[i]));
+            attribute=InterpretImageProperties(msl_info->image_info[n],
+              msl_info->attributes[n],(const char *) attributes[i]);
+            CloneString(&value,attribute);
+            attribute=DestroyString(attribute);
             switch (*keyword)
             {
               case 'F':
@@ -5042,6 +5088,7 @@ static void MSLStartElement(void *contex
               attribute=InterpretImageProperties(msl_info->image_info[n],
                 msl_info->attributes[n],(const char *) attributes[i]);
               CloneString(&value,attribute);
+              attribute=DestroyString(attribute);
               switch (*keyword)
               {
                 case 'G':
@@ -5107,8 +5154,10 @@ static void MSLStartElement(void *contex
         for (i=0; (attributes[i] != (const xmlChar *) NULL); i++)
         {
         keyword=(const char *) attributes[i++];
-        CloneString(&value,InterpretImageProperties(msl_info->image_info[n],
-          msl_info->attributes[n],(const char *) attributes[i]));
+        attribute=InterpretImageProperties(msl_info->image_info[n],
+          msl_info->attributes[n],(const char *) attributes[i]);
+        CloneString(&value,attribute);
+        attribute=DestroyString(attribute);
         switch (*keyword)
         {
           case 'G':
@@ -5234,8 +5283,10 @@ static void MSLStartElement(void *contex
       for (i=0; (attributes[i] != (const xmlChar *) NULL); i++)
       {
         keyword=(const char *) attributes[i++];
-        CloneString(&value,InterpretImageProperties(msl_info->image_info[n],
-          msl_info->attributes[n],(const char *) attributes[i]));
+        attribute=InterpretImageProperties(msl_info->image_info[n],
+          msl_info->attributes[n],(const char *) attributes[i]);
+        CloneString(&value,attribute);
+        attribute=DestroyString(attribute);
         switch (*keyword)
         {
           case 'b':
@@ -5354,6 +5405,7 @@ static void MSLStartElement(void *contex
               attribute=InterpretImageProperties(msl_info->image_info[n],
                 msl_info->attributes[n],(const char *) attributes[i]);
               CloneString(&value,attribute);
+              attribute=DestroyString(attribute);
               switch (*keyword)
               {
                 case 'F':
@@ -5460,6 +5512,7 @@ static void MSLStartElement(void *contex
               attribute=InterpretImageProperties(msl_info->image_info[n],
                 msl_info->attributes[n],(const char *) attributes[i]);
               CloneString(&value,attribute);
+              attribute=DestroyString(attribute);
               switch (*keyword)
               {
                 case 'G':
@@ -5534,9 +5587,11 @@ static void MSLStartElement(void *contex
         break;
         for (i=0; (attributes[i] != (const xmlChar *) NULL); i++)
         {
-        keyword=(const char *) attributes[i++];
-        CloneString(&value,InterpretImageProperties(msl_info->image_info[n],
-          msl_info->attributes[n],(const char *) attributes[i]));
+          keyword=(const char *) attributes[i++];
+          attribute=InterpretImageProperties(msl_info->image_info[n],
+            msl_info->attributes[n],(const char *) attributes[i]);
+          CloneString(&value,attribute);
+          attribute=DestroyString(attribute);
         switch (*keyword)
         {
           case 'G':
@@ -5617,6 +5672,7 @@ static void MSLStartElement(void *contex
               attribute=InterpretImageProperties(msl_info->image_info[n],
                 msl_info->attributes[n],(const char *) attributes[i]);
               CloneString(&value,attribute);
+              attribute=DestroyString(attribute);
               switch (*keyword)
               {
                 case 'D':
@@ -5678,8 +5734,10 @@ static void MSLStartElement(void *contex
         for (i=0; (attributes[i] != (const xmlChar *) NULL); i++)
         {
         keyword=(const char *) attributes[i++];
-        CloneString(&value,InterpretImageProperties(msl_info->image_info[n],
-          msl_info->attributes[n],(const char *) attributes[i]));
+        attribute=InterpretImageProperties(msl_info->image_info[n],
+          msl_info->attributes[n],(const char *) attributes[i]);
+        CloneString(&value,attribute);
+        attribute=DestroyString(attribute);
         switch (*keyword)
         {
           case 'D':
@@ -5743,6 +5801,7 @@ static void MSLStartElement(void *contex
               attribute=InterpretImageProperties(msl_info->image_info[n],
                 msl_info->attributes[n],(const char *) attributes[i]);
               CloneString(&value,attribute);
+              attribute=DestroyString(attribute);
               switch (*keyword)
               {
                 case 'G':
@@ -5819,6 +5878,7 @@ static void MSLStartElement(void *contex
               attribute=InterpretImageProperties(msl_info->image_info[n],
                 msl_info->attributes[n],(const char *) attributes[i]);
               CloneString(&value,attribute);
+              attribute=DestroyString(attribute);
               switch (*keyword)
               {
                 case 'G':
@@ -5902,6 +5962,7 @@ static void MSLStartElement(void *contex
               attribute=InterpretImageProperties(msl_info->image_info[n],
                 msl_info->attributes[n],(const char *) attributes[i]);
               CloneString(&value,attribute);
+              attribute=DestroyString(attribute);
               switch (*keyword)
               {
                 case 'C':
@@ -5979,8 +6040,10 @@ static void MSLStartElement(void *contex
         for (i=0; (attributes[i] != (const xmlChar *) NULL); i++)
         {
           keyword=(const char *) attributes[i++];
-          CloneString(&value,InterpretImageProperties(msl_info->image_info[n],
-            msl_info->attributes[n],(const char *) attributes[i]));
+          attribute=InterpretImageProperties(msl_info->image_info[n],
+            msl_info->attributes[n],(const char *) attributes[i]);
+          CloneString(&value,attribute);
+          attribute=DestroyString(attribute);
           switch (*keyword)
           {
             case 'C':
@@ -6147,6 +6210,7 @@ static void MSLStartElement(void *contex
               attribute=InterpretImageProperties(msl_info->image_info[n],
                 msl_info->attributes[n],(const char *) attributes[i]);
               CloneString(&value,attribute);
+              attribute=DestroyString(attribute);
               switch (*keyword)
               {
                 case 'A':
@@ -6236,6 +6300,7 @@ static void MSLStartElement(void *contex
               attribute=InterpretImageProperties(msl_info->image_info[n],
                 msl_info->attributes[n],(const char *) attributes[i]);
               CloneString(&value,attribute);
+              attribute=DestroyString(attribute);
               switch (*keyword)
               {
                 case 'G':
@@ -6335,8 +6400,10 @@ static void MSLStartElement(void *contex
           for (i=0; (attributes[i] != (const xmlChar *) NULL); i++)
           {
           keyword=(const char *) attributes[i++];
-          CloneString(&value,InterpretImageProperties(msl_info->image_info[n],
-            msl_info->attributes[n],(const char *) attributes[i]));
+          attribute=InterpretImageProperties(msl_info->image_info[n],
+            msl_info->attributes[n],(const char *) attributes[i]);
+          CloneString(&value,attribute);
+          attribute=DestroyString(attribute);
           switch (*keyword)
           {
             case 'R':
@@ -6401,9 +6468,11 @@ static void MSLStartElement(void *contex
         break;
         for (i=0; (attributes[i] != (const xmlChar *) NULL); i++)
         {
-        keyword=(const char *) attributes[i++];
-        CloneString(&value,InterpretImageProperties(msl_info->image_info[n],
-          msl_info->attributes[n],(const char *) attributes[i]));
+          keyword=(const char *) attributes[i++];
+          attribute=InterpretImageProperties(msl_info->image_info[n],
+            msl_info->attributes[n],(const char *) attributes[i]);
+          CloneString(&value,attribute);
+          attribute=DestroyString(attribute);
         switch (*keyword)
         {
           case 'G':
@@ -6493,6 +6562,7 @@ static void MSLStartElement(void *contex
               attribute=InterpretImageProperties(msl_info->image_info[n],
                 msl_info->attributes[n],(const char *) attributes[i]);
               CloneString(&value,attribute);
+              attribute=DestroyString(attribute);
               switch (*keyword)
               {
                 case 'F':
@@ -6581,6 +6651,7 @@ static void MSLStartElement(void *contex
               attribute=InterpretImageProperties(msl_info->image_info[n],
                 msl_info->attributes[n],(const char *) attributes[i]);
               CloneString(&value,attribute);
+              attribute=DestroyString(attribute);
               switch (*keyword)
               {
                 default:
@@ -6613,6 +6684,7 @@ static void MSLStartElement(void *contex
               attribute=InterpretImageProperties(msl_info->image_info[n],
                 msl_info->attributes[n],(const char *) attributes[i]);
               CloneString(&value,attribute);
+              attribute=DestroyString(attribute);
               switch (*keyword)
               {
                 case 'G':
@@ -6672,6 +6744,7 @@ static void MSLStartElement(void *contex
               attribute=InterpretImageProperties(msl_info->image_info[n],
                 msl_info->attributes[n],(const char *) attributes[i]);
               CloneString(&value,attribute);
+              attribute=DestroyString(attribute);
               switch (*keyword)
               {
                 case 'G':
@@ -6732,9 +6805,11 @@ static void MSLStartElement(void *contex
         break;
         for (i=0; (attributes[i] != (const xmlChar *) NULL); i++)
         {
-        keyword=(const char *) attributes[i++];
-        CloneString(&value,InterpretImageProperties(msl_info->image_info[n],
-          msl_info->attributes[n],(const char *) attributes[i]));
+          keyword=(const char *) attributes[i++];
+          attribute=InterpretImageProperties(msl_info->image_info[n],
+            msl_info->attributes[n],(const char *) attributes[i]);
+          CloneString(&value,attribute);
+          attribute=DestroyString(attribute);
         switch (*keyword)
         {
           case 'I':
@@ -6796,9 +6871,11 @@ static void MSLStartElement(void *contex
         break;
         for (i=0; (attributes[i] != (const xmlChar *) NULL); i++)
         {
-        keyword=(const char *) attributes[i++];
-        CloneString(&value,InterpretImageProperties(msl_info->image_info[n],
-          msl_info->attributes[n],(const char *) attributes[i]));
+          keyword=(const char *) attributes[i++];
+          attribute=InterpretImageProperties(msl_info->image_info[n],
+            msl_info->attributes[n],(const char *) attributes[i]);
+          CloneString(&value,attribute);
+          attribute=DestroyString(attribute);
         switch (*keyword)
         {
           case 'I':
@@ -6864,6 +6941,7 @@ static void MSLStartElement(void *contex
               attribute=InterpretImageProperties(msl_info->image_info[n],
                 msl_info->attributes[n],(const char *) attributes[i]);
               CloneString(&value,attribute);
+              attribute=DestroyString(attribute);
               ThrowMSLException(OptionError,"UnrecognizedAttribute",keyword);
             }
           (void) StripImage(msl_info->image[n]);
@@ -6895,6 +6973,7 @@ static void MSLStartElement(void *contex
               attribute=InterpretImageProperties(msl_info->image_info[n],
                 msl_info->attributes[n],(const char *) attributes[i]);
               CloneString(&value,attribute);
+              attribute=DestroyString(attribute);
               switch (*keyword)
               {
                 case 'G':
@@ -6957,6 +7036,7 @@ static void MSLStartElement(void *contex
               attribute=InterpretImageProperties(msl_info->image_info[n],
                 msl_info->attributes[n],(const char *) attributes[i]);
               CloneString(&value,attribute);
+              attribute=DestroyString(attribute);
               switch (*keyword)
               {
                 case 'D':
@@ -7020,6 +7100,7 @@ static void MSLStartElement(void *contex
               attribute=InterpretImageProperties(msl_info->image_info[n],
                 msl_info->attributes[n],(const char *) attributes[i]);
               CloneString(&value,attribute);
+              attribute=DestroyString(attribute);
               switch (*keyword)
               {
                 default:
@@ -7060,6 +7141,7 @@ static void MSLStartElement(void *contex
               attribute=InterpretImageProperties(msl_info->image_info[n],
                 msl_info->attributes[n],(const char *) attributes[i]);
               CloneString(&value,attribute);
+              attribute=DestroyString(attribute);
               switch (*keyword)
               {
                 case 'I':
@@ -7108,9 +7190,11 @@ static void MSLStartElement(void *contex
         break;
         for (i=0; (attributes[i] != (const xmlChar *) NULL); i++)
         {
-        keyword=(const char *) attributes[i++];
-        CloneString(&value,InterpretImageProperties(msl_info->image_info[n],
-          msl_info->attributes[n],(const char *) attributes[i]));
+          keyword=(const char *) attributes[i++];
+          attribute=InterpretImageProperties(msl_info->image_info[n],
+            msl_info->attributes[n],(const char *) attributes[i]);
+          CloneString(&value,attribute);
+          attribute=DestroyString(attribute);
         switch (*keyword)
         {
           case 'T':
@@ -7154,8 +7238,10 @@ static void MSLStartElement(void *contex
         for (i=0; (attributes[i] != (const xmlChar *) NULL); i++)
         {
           keyword=(const char *) attributes[i++];
-          CloneString(&value,InterpretImageProperties(msl_info->image_info[n],
-            msl_info->attributes[n],(const char *) attributes[i]));
+          attribute=InterpretImageProperties(msl_info->image_info[n],
+            msl_info->attributes[n],(const char *) attributes[i]);
+          CloneString(&value,attribute);
+          attribute=DestroyString(attribute);
           switch (*keyword)
           {
             case 'C':
@@ -7230,8 +7316,10 @@ static void MSLStartElement(void *contex
           for (i=0; (attributes[i] != (const xmlChar *) NULL); i++)
           {
             keyword=(const char *) attributes[i++];
-            CloneString(&value,InterpretImageProperties(msl_info->image_info[n],
-              msl_info->attributes[n],(const char *) attributes[i]));
+            attribute=InterpretImageProperties(msl_info->image_info[n],
+              msl_info->attributes[n],(const char *) attributes[i]);
+            CloneString(&value,attribute);
+            attribute=DestroyString(attribute);
             switch (*keyword)
             {
               case 'F':
@@ -8183,14 +8271,22 @@ ModuleExport void UnregisterMSLImage(voi
 */
 static MagickBooleanType WriteMSLImage(const ImageInfo *image_info,Image *image)
 {
+  Image
+    *msl_image;
+
+  MagickBooleanType
+    status;
+
   assert(image_info != (const ImageInfo *) NULL);
   assert(image_info->signature == MagickSignature);
   assert(image != (Image *) NULL);
   assert(image->signature == MagickSignature);
   if (image->debug != MagickFalse)
     (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
-  (void) ReferenceImage(image);
-  (void) ProcessMSLScript(image_info,&image,&image->exception);
-  return(MagickTrue);
+  msl_image=CloneImage(image,0,0,MagickTrue,&image->exception);
+  status=ProcessMSLScript(image_info,&msl_image,&image->exception);
+  if (msl_image)
+    msl_image=DestroyImage(msl_image);
+  return(status);
 }
 #endif