File libcdio-0.94-leak-14.patch of Package libcdio.7811

Partial patch.
From 6322324ea52ffd128e75267221d70eea1c4d87bd Mon Sep 17 00:00:00 2001
From: "R. Bernstein" <rocky@gnu.org>
Date: Thu, 7 Dec 2017 22:45:48 -0500
Subject: [PATCH 14/20] Another pass at removing memory leaks

---
 lib/driver/_cdio_generic.c |  2 ++
 lib/driver/aix.c           |  4 +++-
 lib/driver/solaris.c       |  2 ++
 src/iso-info.c             |  2 +-
 src/mmc-tool.c             | 31 ++++++++++++++++++++++++-------
 5 files changed, 32 insertions(+), 9 deletions(-)

diff --git a/lib/driver/_cdio_generic.c b/lib/driver/_cdio_generic.c
index e84ee314..d40ac0d9 100644
--- a/lib/driver/_cdio_generic.c
+++ b/lib/driver/_cdio_generic.c
@@ -319,6 +319,8 @@ get_discmode_generic (void *p_user_data )
   /* See if this is a DVD. */
   cdio_dvd_struct_t dvd;  /* DVD READ STRUCT for layer 0. */
 
+  memset(&dvd, 0, sizeof(dvd));
+
   dvd.physical.type = CDIO_DVD_STRUCT_PHYSICAL;
   dvd.physical.layer_num = 0;
   if (0 == mmc_get_dvd_struct_physical (p_env->cdio, &dvd)) {
diff --git a/lib/driver/aix.c b/lib/driver/aix.c
index b9312ae0..5af33c4e 100644
--- a/lib/driver/aix.c
+++ b/lib/driver/aix.c
@@ -1,5 +1,5 @@
 /*
-  Copyright (C) 2004-2006, 2008, 2010, 2011-2013
+  Copyright (C) 2004-2006, 2008, 2010, 2011-2013, 2017
   Rocky Bernstein <rocky@gnu.org>
 
   This program is free software: you can redistribute it and/or modify
@@ -727,6 +727,8 @@ get_discmode_aix (void *p_user_data)
   struct mode_form_op media;
   int ret;
 
+  memset(&media, 0, sizeof(media));
+
   /* Get the media info */
   media.action= CD_GET_MODE;
 
diff --git a/lib/driver/solaris.c b/lib/driver/solaris.c
index c32e6b12..12aee966 100644
--- a/lib/driver/solaris.c
+++ b/lib/driver/solaris.c
@@ -883,6 +883,8 @@ get_discmode_solaris (void *p_user_data)
   struct dk_minfo media;
   int ret;
 
+  memset(&media, 0, sizeof(media));
+
   /* Get the media info */
   if((ret = ioctl(p_env->gen.fd, DKIOCGMEDIAINFO, &media)) != 0) {
      cdio_warn ("DKIOCGMEDIAINFO failed: %s\n", strerror(errno));
diff --git a/src/mmc-tool.c b/src/mmc-tool.c
index 439abcdc..1fdb6b27 100644
--- a/src/mmc-tool.c
+++ b/src/mmc-tool.c
@@ -38,12 +38,6 @@
 #include <cdio/mmc_cmds.h>
 #include "getopt.h"
 
-static void
-init(const char *argv0)
-{
-  program_name = strrchr(argv0,'/');
-  program_name = program_name ? strdup(program_name+1) : strdup(argv0);
-}
 
 /* Configuration option codes */
 typedef enum {
@@ -259,6 +253,26 @@ parse_options (int argc, char *argv[])
   return true;
 }
 
+static void
+_log_handler (cdio_log_level_t level, const char message[])
+{
+  if (level == CDIO_LOG_ERROR) {
+    // print an error like default, but *don't* exit.
+    fprintf (stderr, "**ERROR: %s\n", message);
+    fflush (stderr);
+    return;
+  }
+  gl_default_cdio_log_handler (level, message);
+}
+
+static void
+init(const char *argv0)
+{
+  gl_default_cdio_log_handler = cdio_log_set_handler (_log_handler);
+  program_name = strrchr(argv0,'/');
+  program_name = program_name ? strdup(program_name+1) : strdup(argv0);
+}
+
 static void
 print_mode_sense (unsigned int i_mmc_size, const uint8_t buf[30])
 {
@@ -431,7 +445,8 @@ main(int argc, char *argv[])
 
   if (NULL == p_cdio) {
     printf("Couldn't find CD\n");
-    return 1;
+    rc = 1;
+    goto exit;
   }
 
   for (i=0; i < last_op; i++) {
@@ -521,7 +536,9 @@ main(int argc, char *argv[])
     }
   }
 
+ exit:
   free(source_name);
+  free(program_name);
   cdio_destroy(p_cdio);
 
   return rc;
-- 
2.17.0
openSUSE Build Service is sponsored by