From: Cristy <urban-warrior@imagemagick.org>
Date: Tue, 15 Mar 2022 21:59:36 -0400
Subject: Fix CVE-2022-1114: Heap use after free in RelinquishDCMInfo()

bug: https://github.com/ImageMagick/ImageMagick/issues/4947
bug-debian: https://bugs.debian.org/1013282
origin: https://github.com/ImageMagick/ImageMagick6/commit/78f03b619d08d7c2e0fcaccab407e3ac93c2ee8f.patch
---
 coders/dcm.c | 14 +++++++-------
 1 file changed, 7 insertions(+), 7 deletions(-)

diff --git a/coders/dcm.c b/coders/dcm.c
index d274ad..439aa 100644
--- a/coders/dcm.c
+++ b/coders/dcm.c
@@ -3242,15 +3242,15 @@ static Image *ReadDCMImage(const ImageInfo *image_info,ExceptionInfo *exception)
           RelinquishMagickMemory(info_copy);
         }
 
-      /*
-        If we're entering a sequence, push the current image parameters onto
-        the stack, so we can restore them at the end of the sequence.
-      */
       if (strcmp(explicit_vr,"SQ") == 0)
         {
-          DCMInfo *info_copy = (DCMInfo *) AcquireMagickMemory(sizeof(info));
-          memcpy(info_copy,&info,sizeof(info));
-          AppendValueToLinkedList(stack,info_copy);
+          /*
+            If we're entering a sequence, push the current image parameters
+            onto the stack, so we can restore them at the end of the sequence.
+          */
+          DCMInfo *clone_info = (DCMInfo *) AcquireMagickMemory(sizeof(info));
+          (void) memcpy(clone_info,&info,sizeof(info));
+          AppendValueToLinkedList(stack,clone_info);
           sequence_depth++;
         }
 
