<html><head><meta name="color-scheme" content="light dark"></head><body><pre style="word-wrap: break-word; white-space: pre-wrap;">From 4166b143940e3317da48f5b69da2729bd8fd380e Mon Sep 17 00:00:00 2001
From: Thomas Schmitt &lt;scdbackup@gmx.net&gt;
Date: Mon, 18 May 2020 17:36:13 +0100
Subject: [PATCH 1/1] Fix use of iso9660_stat_free() where appropriate.

---
 example/C++/isofile.cpp    |  4 ++--
 example/C++/isofile2.cpp   |  6 +++---
 example/isofile.c          |  6 +++---
 example/isofile2.c         |  6 +++---
 include/cdio++/iso9660.hpp |  4 ++--
 lib/iso9660/iso9660_fs.c   | 25 +++++++++++--------------
 src/iso-read.c             |  1 +
 7 files changed, 25 insertions(+), 27 deletions(-)

diff --git a/example/C++/isofile.cpp b/example/C++/isofile.cpp
index fdb84228..d1eeec20 100644
--- a/example/C++/isofile.cpp
+++ b/example/C++/isofile.cpp
@@ -57,7 +57,7 @@
 
 #define my_exit(rc)				\
   fclose (p_outfd);				\
-  free(p_statbuf);				\
+  iso9660_stat_free(p_statbuf);			\
   iso9660_close(p_iso);				\
   return rc;					\
 
@@ -108,7 +108,7 @@ main(int argc, const char *argv[])
   if (!(p_outfd = fopen (psz_fname, "wb")))
     {
       perror ("fopen()");
-      free(p_statbuf);
+      iso9660_stat_free(p_statbuf);
       iso9660_close(p_iso);
       return 3;
     }
diff --git a/example/C++/isofile2.cpp b/example/C++/isofile2.cpp
index 838e2dd1..035528bf 100644
--- a/example/C++/isofile2.cpp
+++ b/example/C++/isofile2.cpp
@@ -57,8 +57,8 @@
 
 #define my_exit(rc)				\
   fclose (p_outfd);				\
-  free(p_statbuf);				\
-  iso9660_close(p_iso);				\
+  iso9660_stat_free(p_statbuf);	\
+  iso9660_close(p_iso);			\
   return rc;					\
 
 int
@@ -108,7 +108,7 @@ main(int argc, const char *argv[])
   if (!(p_outfd = fopen (psz_fname, "wb")))
     {
       perror ("fopen()");
-      free(p_statbuf);
+      iso9660_stat_free(p_statbuf);
       iso9660_close(p_iso);
       return 3;
     }
diff --git a/example/isofile.c b/example/isofile.c
index bcfe06a5..2c582ed2 100644
--- a/example/isofile.c
+++ b/example/isofile.c
@@ -58,8 +58,8 @@
 
 #define my_exit(rc)				\
   fclose (p_outfd);				\
-  free(p_statbuf);				\
-  iso9660_close(p_iso);				\
+  iso9660_stat_free(p_statbuf);	\
+  iso9660_close(p_iso);			\
   return rc;					\
 
 int
@@ -109,7 +109,7 @@ main(int argc, const char *argv[])
   if (!(p_outfd = fopen (psz_fname, "wb")))
     {
       perror ("fopen()");
-      free(p_statbuf);
+      iso9660_stat_free(p_statbuf);
       iso9660_close(p_iso);
       return 3;
     }
diff --git a/example/isofile2.c b/example/isofile2.c
index 7148f2fb..a5cd0397 100644
--- a/example/isofile2.c
+++ b/example/isofile2.c
@@ -69,8 +69,8 @@
 
 #define my_exit(rc)				\
   fclose (p_outfd);				\
-  free(p_statbuf);				\
-  cdio_destroy(p_cdio);				\
+  iso9660_stat_free(p_statbuf);	\
+  cdio_destroy(p_cdio);			\
   return rc;					\
 
 
@@ -130,7 +130,7 @@ main(int argc, const char *argv[])
   if (!(p_outfd = fopen (translated_name, "wb"))) {
       perror ("fopen()");
       cdio_destroy(p_cdio);
-      free(p_statbuf);
+      iso9660_stat_free(p_statbuf);
       return 3;
     }
 
diff --git a/include/cdio++/iso9660.hpp b/include/cdio++/iso9660.hpp
index b1ac2f39..dd876643 100644
--- a/include/cdio++/iso9660.hpp
+++ b/include/cdio++/iso9660.hpp
@@ -124,7 +124,7 @@ public:
 
     Stat(const Stat&amp; copy_in)
     {
-      free(p_stat);
+      iso9660_stat_free(p_stat);
       p_stat = (iso9660_stat_t *)
         calloc( 1, sizeof(iso9660_stat_t)
                 + strlen(copy_in.p_stat-&gt;filename)+1 );
@@ -133,7 +133,7 @@ public:
 
     const Stat&amp; operator= (const Stat&amp; right)
     {
-      free(p_stat);
+      iso9660_stat_free(p_stat);
       this-&gt;p_stat = right.p_stat;
       return right;
     }
diff --git a/lib/iso9660/iso9660_fs.c b/lib/iso9660/iso9660_fs.c
index 00cb9ec8..538a90f5 100644
--- a/lib/iso9660/iso9660_fs.c
+++ b/lib/iso9660/iso9660_fs.c
@@ -821,12 +821,10 @@ _iso9660_dir_to_statbuf (iso9660_dir_t *p_iso9660_dir, bool_3way_t b_xa,
 	/* realloc gives valgrind errors */
 	iso9660_stat_t *p_stat_new =
 	  calloc(1, sizeof(iso9660_stat_t)+i_rr_fname+2);
-        if (!p_stat_new)
-          {
-          cdio_warn("Couldn't calloc(1, %d)", (int)(sizeof(iso9660_stat_t)+i_rr_fname+2));
-	  free(p_stat);
-          return NULL;
-          }
+	if (!p_stat_new) {
+	  cdio_warn("Couldn't calloc(1, %d)", (int)(sizeof(iso9660_stat_t)+i_rr_fname+2));
+	  goto fail;
+	}
 	memcpy(p_stat_new, p_stat, stat_len);
 	free(p_stat);
 	p_stat = p_stat_new;
@@ -845,10 +843,8 @@ _iso9660_dir_to_statbuf (iso9660_dir_t *p_iso9660_dir, bool_3way_t b_xa,
                              &amp;p_psz_out, "UCS-2BE")) {
           strncpy(p_stat-&gt;filename, p_psz_out, i_fname);
           free(p_psz_out);
-        }
-        else {
-          free(p_stat);
-          return NULL;
+        } else {
+          goto fail;
         }
       }
 #endif /*HAVE_JOLIET*/
@@ -861,10 +857,8 @@ _iso9660_dir_to_statbuf (iso9660_dir_t *p_iso9660_dir, bool_3way_t b_xa,
 
   iso9660_get_dtime(&amp;(p_iso9660_dir-&gt;recording_time), true, &amp;(p_stat-&gt;tm));
 
-  if (dir_len &lt; sizeof (iso9660_dir_t)) {
-    iso9660_stat_free(p_stat);
-    return NULL;
-  }
+  if (dir_len &lt; sizeof (iso9660_dir_t))
+    goto fail;
 
 
   {
@@ -907,6 +901,9 @@ _iso9660_dir_to_statbuf (iso9660_dir_t *p_iso9660_dir, bool_3way_t b_xa,
   }
   return p_stat;
 
+fail:
+  iso9660_stat_free(p_stat);
+  return NULL;
 }
 
 /*!
diff --git a/src/iso-read.c b/src/iso-read.c
index 86474859..852112ae 100644
--- a/src/iso-read.c
+++ b/src/iso-read.c
@@ -266,6 +266,7 @@ static int read_iso_file(const char *iso_name, const char *src,
   iso9660_close(iso);
 
   *bytes_written = statbuf-&gt;size;
+  iso9660_stat_free(statbuf);
   return 0;
 }
 
-- 
2.50.0

</pre></body></html>