]> granicus.if.org Git - imagemagick/blobdiff - coders/dot.c
Fixed memory leak reported in #456.
[imagemagick] / coders / dot.c
index 27bae00751790fa62279a79cc2202da8c8a593d8..fc0a3990291076305e6b915815aaaef6ec853bb6 100644 (file)
 %                                 July 1992                                   %
 %                                                                             %
 %                                                                             %
-%  Copyright 1999-2015 ImageMagick Studio LLC, a non-profit organization      %
+%  Copyright 1999-2017 ImageMagick Studio LLC, a non-profit organization      %
 %  dedicated to making software imaging solutions freely available.           %
 %                                                                             %
 %  You may not use this file except in compliance with the License.  You may  %
 %  obtain a copy of the License at                                            %
 %                                                                             %
-%    http://www.imagemagick.org/script/license.php                            %
+%    https://www.imagemagick.org/script/license.php                           %
 %                                                                             %
 %  Unless required by applicable law or agreed to in writing, software        %
 %  distributed under the License is distributed on an "AS IS" BASIS,          %
@@ -65,7 +65,7 @@
 #undef HAVE_CONFIG_H
 #include <gvc.h>
 static GVC_t
-  *graphic_context;
+  *graphic_context = (GVC_t *) NULL;
 #endif
 \f
 #if defined(MAGICKCORE_GVC_DELEGATE)
@@ -98,7 +98,7 @@ static GVC_t
 static Image *ReadDOTImage(const ImageInfo *image_info,ExceptionInfo *exception)
 {
   char
-    command[MaxTextExtent];
+    command[MagickPathExtent];
 
   const char
     *option;
@@ -119,21 +119,22 @@ static Image *ReadDOTImage(const ImageInfo *image_info,ExceptionInfo *exception)
     Open image file.
   */
   assert(image_info != (const ImageInfo *) NULL);
-  assert(image_info->signature == MagickSignature);
+  assert(image_info->signature == MagickCoreSignature);
   if (image_info->debug != MagickFalse)
     (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",
       image_info->filename);
   assert(exception != (ExceptionInfo *) NULL);
-  assert(exception->signature == MagickSignature);
+  assert(exception->signature == MagickCoreSignature);
+  assert(graphic_context != (GVC_t *) NULL);
   image=AcquireImage(image_info,exception);
   status=OpenBlob(image_info,image,ReadBinaryBlobMode,exception);
   if (status == MagickFalse)
     return((Image *) NULL);
   read_info=CloneImageInfo(image_info);
   SetImageInfoBlob(read_info,(void *) NULL,0);
-  (void) CopyMagickString(read_info->magick,"SVG",MaxTextExtent);
+  (void) CopyMagickString(read_info->magick,"SVG",MagickPathExtent);
   (void) AcquireUniqueFilename(read_info->filename);
-  (void) FormatLocaleString(command,MaxTextExtent,"-Tsvg -o%s %s",
+  (void) FormatLocaleString(command,MagickPathExtent,"-Tsvg -o%s %s",
     read_info->filename,image_info->filename);
 #if !defined(WITH_CGRAPH)
   graph=agread(GetBlobFileHandle(image));
@@ -193,21 +194,17 @@ ModuleExport size_t RegisterDOTImage(void)
   MagickInfo
     *entry;
 
-  entry=SetMagickInfo("DOT");
+  entry=AcquireMagickInfo("DOT","DOT","Graphviz");
 #if defined(MAGICKCORE_GVC_DELEGATE)
   entry->decoder=(DecodeImageHandler *) ReadDOTImage;
 #endif
   entry->flags^=CoderBlobSupportFlag;
-  entry->description=ConstantString("Graphviz");
-  entry->module=ConstantString("DOT");
   (void) RegisterMagickInfo(entry);
-  entry=SetMagickInfo("GV");
+  entry=AcquireMagickInfo("DOT","GV","Graphviz");
 #if defined(MAGICKCORE_GVC_DELEGATE)
   entry->decoder=(DecodeImageHandler *) ReadDOTImage;
 #endif
   entry->flags^=CoderBlobSupportFlag;
-  entry->description=ConstantString("Graphviz");
-  entry->module=ConstantString("DOT");
   (void) RegisterMagickInfo(entry);
 #if defined(MAGICKCORE_GVC_DELEGATE)
   graphic_context=gvContext();
@@ -239,6 +236,10 @@ ModuleExport void UnregisterDOTImage(void)
   (void) UnregisterMagickInfo("GV");
   (void) UnregisterMagickInfo("DOT");
 #if defined(MAGICKCORE_GVC_DELEGATE)
-  gvFreeContext(graphic_context);
+  if (graphic_context != (GVC_t *) NULL)
+    {
+      gvFreeContext(graphic_context);
+      graphic_context=(GVC_t *) NULL;
+    }
 #endif
 }