GraphicsMagick: coders/topol.c: Fix memory leak.

GraphicsMagick Commits <[email protected]>
Newsgroups gmane.comp.video.graphicsmagick.cvs
Message-ID <mailman.576.1683237761.1366.graphicsmagick-commit@lists.sourceforge.net>
changeset 51ef76f15c08 in /hg/GraphicsMagick
details: http://hg.GraphicsMagick.org/hg/GraphicsMagick?cmd=changeset;node=51ef76f15c08
summary: coders/topol.c: Fix memory leak.

diffstat:

 ChangeLog      |   4 ++++
 coders/topol.c |  16 ++++++++--------
 2 files changed, 12 insertions(+), 8 deletions(-)

diffs (81 lines):

diff -r a7dfeb349989 -r 51ef76f15c08 ChangeLog
--- a/ChangeLog	Thu May 04 08:31:06 2023 -0500
+++ b/ChangeLog	Fri May 05 00:02:08 2023 +0200
@@ -1,5 +1,9 @@
 2023-05-05  Fojtik Jaroslav  <[email protected]>
 
+	* coders/topol.c: Fix memory leak.
+
+2023-05-04  Fojtik Jaroslav  <[email protected]>
+
 	* coders/topol.c: Provide function IsTopoL.
 
 2023-05-03  Fojtik Jaroslav  <[email protected]>
diff -r a7dfeb349989 -r 51ef76f15c08 coders/topol.c
--- a/coders/topol.c	Thu May 04 08:31:06 2023 -0500
+++ b/coders/topol.c	Fri May 05 00:02:08 2023 +0200
@@ -420,9 +420,8 @@
     status;
 
   size_t i;
-  long
-    j,
-    ldblk;
+  unsigned long j;
+  long ldblk;
 
   unsigned char
     *BImgBuff = NULL,
@@ -488,7 +487,7 @@
     }
   if(image->logging) LogHeaderTopoL(&Header);
 
-  for (i = 0; i < (long) sizeof(Header.Name); i++)
+  for(i=0; i<sizeof(Header.Name); i++)
     {
       if (Header.Name[i] < ' ')
 TOPOL_KO:              ThrowTOPOLReaderException(CorruptImageError,ImproperImageHeader, image);
@@ -577,7 +576,7 @@
   status=OpenBlob(clone_info,palette,ReadBinaryBlobMode,exception);
   if (status == False) goto NoMEZ;
 
-  ldblk=(long) GetBlobSize(palette);
+  ldblk = (long)GetBlobSize(palette);
   if ( ldblk > (long) sizeof(MEZ))
     ldblk=sizeof(MEZ);
   (void) ReadBlob(palette, ldblk, MEZ);
@@ -665,7 +664,7 @@
           ThrowTOPOLReaderException(ResourceLimitError, MemoryAllocationFailed, image);
       }
 
-      for(i = 0; i < (long) image->colors; i++)
+      for(i = 0; i < image->colors; i++)
       {
         j = MEZ[i];
         image->colormap[i].red = ScaleCharToQuantum(j);
@@ -685,7 +684,7 @@
      if (BImgBuff == NULL)
         ThrowTOPOLReaderException(ResourceLimitError, MemoryAllocationFailed, image);
      (void) SeekBlob(image, 512 /*sizeof(Header)*/, SEEK_SET);
-     for (i = 0; i < (int) Header.Rows; i++)
+     for (i = 0; i < Header.Rows; i++)
      {
        if (ReadBlob(image, ldblk, (char *)BImgBuff) != (size_t) ldblk)
          ThrowTOPOLReaderException(CorruptImageError,UnexpectedEndOfFile,image);
@@ -936,7 +935,7 @@
       if((clone_info->file=fopen(clone_info->filename,"wb"))!=NULL)
       {
         Image *Palette;
-        if((Palette=AllocateImage(clone_info))!=NULL )
+        if((Palette=AllocateImage(clone_info)) != NULL)
         {
           ExceptionInfo exception;
           if(OpenBlob(clone_info,Palette,WriteBinaryBlobMode,&exception))
@@ -964,6 +963,7 @@
               }
             }
           }
+          DestroyImage(Palette);
         }
       }
       DestroyImageInfo(clone_info);
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.