GraphicsMagick: coders/tiff.c: Avoid memory leak in TIFFCreateDi...

GraphicsMagick Commits <[email protected]> Thu, 25 Jan 2024 16:45:55 -0600
Newsgroups gmane.comp.video.graphicsmagick.cvs
Message-ID <mailman.6247.1706222768.16032.graphicsmagick-commit@lists.sourceforge.net>
changeset e125fe5e0afa in /hg/GraphicsMagick
details: http://hg.GraphicsMagick.org/hg/GraphicsMagick?cmd=changeset;node=e125fe5e0afa
summary: coders/tiff.c: Avoid memory leak in TIFFCreateDirectory() for libtiff versions which do not call TIFFFreeDirectory()

diffstat:

 ChangeLog                              |   7 +++++++
 VisualMagick/installer/inc/version.isx |   4 ++--
 coders/tiff.c                          |   4 ++++
 magick/version.h                       |   4 ++--
 www/Changelog.html                     |  11 ++++++++++-
 5 files changed, 25 insertions(+), 5 deletions(-)

diffs (98 lines):

diff -r f006632acae4 -r e125fe5e0afa ChangeLog
--- a/ChangeLog	Wed Jan 24 07:53:43 2024 -0600
+++ b/ChangeLog	Thu Jan 25 16:45:50 2024 -0600
@@ -1,3 +1,10 @@
+2024-01-25  Bob Friesenhahn  <[email protected]>
+
+	* coders/tiff.c (WriteTIFFImage): TIFFFreeDirectory() statements
+	necessary to avoid memory leak in libtiff versions lacking merge
+	request 563 "Avoiding memory leaks when using
+	TIFFCreateDirectory()".
+
 2024-01-24  Bob Friesenhahn  <[email protected]>
 
 	* coders/jxl.c: Directly include jxl/version.h rather than
diff -r f006632acae4 -r e125fe5e0afa VisualMagick/installer/inc/version.isx
--- a/VisualMagick/installer/inc/version.isx	Wed Jan 24 07:53:43 2024 -0600
+++ b/VisualMagick/installer/inc/version.isx	Thu Jan 25 16:45:50 2024 -0600
@@ -10,5 +10,5 @@
 
 #define public MagickPackageName "GraphicsMagick"
 #define public MagickPackageVersion "1.4"
-#define public MagickPackageVersionAddendum ".020240124"
-#define public MagickPackageReleaseDate "snapshot-20240124"
+#define public MagickPackageVersionAddendum ".020240125"
+#define public MagickPackageReleaseDate "snapshot-20240125"
diff -r f006632acae4 -r e125fe5e0afa coders/tiff.c
--- a/coders/tiff.c	Wed Jan 24 07:53:43 2024 -0600
+++ b/coders/tiff.c	Thu Jan 25 16:45:50 2024 -0600
@@ -6781,9 +6781,11 @@
 #if EXPERIMENTAL_EXIF_TAGS
 #if TIFFLIB_VERSION >= 20120922
 
+#if 0
 /* !!!!!!!!!!!!!!! */
         if(image->next == (Image *)NULL)	/* This  should be removed, one time fix */
 /* !!!!!!!!!!!!!!! */
+#endif
 
         if(status!=MagickFail)
         {
@@ -6799,6 +6801,7 @@
             tdir_t current_mainifd = TIFFCurrentDirectory(tiff);
             if(TIFFCurrentDirOffset(tiff) > 0 && current_mainifd > 0) current_mainifd--;
 
+            TIFFFreeDirectory(tiff);
             if(TIFFCreateEXIFDirectory(tiff) == 0)
             {
               if(AddExifFields(tiff,profile_data,profile_length,logging, FLAG_EXIF) > 0)
@@ -6848,6 +6851,7 @@
                 if(logging)
                   LogMagickEvent(CoderEvent,GetMagickModule(),"TIFFSetDirectory() failed.\n");
               }
+              TIFFFreeDirectory(tiff);
               if(!TIFFCreateDirectory(tiff))
               {
                 if(logging)
diff -r f006632acae4 -r e125fe5e0afa magick/version.h
--- a/magick/version.h	Wed Jan 24 07:53:43 2024 -0600
+++ b/magick/version.h	Thu Jan 25 16:45:50 2024 -0600
@@ -38,8 +38,8 @@
 #define MagickLibVersion  0x272404
 #define MagickLibVersionText  "1.4"
 #define MagickLibVersionNumber 27,24,4
-#define MagickChangeDate   "20240124"
-#define MagickReleaseDate  "snapshot-20240124"
+#define MagickChangeDate   "20240125"
+#define MagickReleaseDate  "snapshot-20240125"
 
 /*
   The MagickLibInterfaceNewest and MagickLibInterfaceOldest defines
diff -r f006632acae4 -r e125fe5e0afa www/Changelog.html
--- a/www/Changelog.html	Wed Jan 24 07:53:43 2024 -0600
+++ b/www/Changelog.html	Thu Jan 25 16:45:50 2024 -0600
@@ -37,6 +37,15 @@
 </div>
 
 <div class="document">
+<p>2024-01-25  Bob Friesenhahn  &lt;<a class="reference external" href="mailto:bfriesen&#37;&#52;&#48;simple&#46;dallas&#46;tx&#46;us">bfriesen<span>&#64;</span>simple<span>&#46;</span>dallas<span>&#46;</span>tx<span>&#46;</span>us</a>&gt;</p>
+<blockquote>
+<ul class="simple">
+<li><p>coders/tiff.c (WriteTIFFImage): TIFFFreeDirectory() statements
+necessary to avoid memory leak in libtiff versions lacking merge
+request 563 &quot;Avoiding memory leaks when using
+TIFFCreateDirectory()&quot;.</p></li>
+</ul>
+</blockquote>
 <p>2024-01-24  Bob Friesenhahn  &lt;<a class="reference external" href="mailto:bfriesen&#37;&#52;&#48;simple&#46;dallas&#46;tx&#46;us">bfriesen<span>&#64;</span>simple<span>&#46;</span>dallas<span>&#46;</span>tx<span>&#46;</span>us</a>&gt;</p>
 <blockquote>
 <ul class="simple">
@@ -55,7 +64,7 @@
 </ul>
 </blockquote>
 <div class="system-message">
-<p class="system-message-title">System Message: WARNING/2 (<span class="docutils literal">&lt;string&gt;</span>, line 13)</p>
+<p class="system-message-title">System Message: WARNING/2 (<span class="docutils literal">&lt;string&gt;</span>, line 20)</p>
 <p>Block quote ends without a blank line; unexpected unindent.</p>
 </div>
 <p>2024-01-23  Fojtik Jaroslav  &lt;<a class="reference external" href="mailto:JaFojtik&#37;&#52;&#48;yandex&#46;com">JaFojtik<span>&#64;</span>yandex<span>&#46;</span>com</a>&gt;</p>