From 9c013946f6f68f87d0ad5a600d35f5d6bc5d4313 Mon Sep 17 00:00:00 2001 From: Thomas Schmitt Date: Wed, 25 Nov 2015 09:34:07 +0000 Subject: [PATCH] Fixed a theoretical memory leak in actually unused code. Reported by cppcheck. --- libburn/trunk/cdrskin/cdrskin_timestamp.h | 2 +- libburn/trunk/libburn/sg-freebsd.c | 17 +++++++++++++++++ 2 files changed, 18 insertions(+), 1 deletion(-) diff --git a/libburn/trunk/cdrskin/cdrskin_timestamp.h b/libburn/trunk/cdrskin/cdrskin_timestamp.h index f74cbb54..d2ed91cf 100644 --- a/libburn/trunk/cdrskin/cdrskin_timestamp.h +++ b/libburn/trunk/cdrskin/cdrskin_timestamp.h @@ -1 +1 @@ -#define Cdrskin_timestamP "2015.11.02.151241" +#define Cdrskin_timestamP "2015.11.25.093414" diff --git a/libburn/trunk/libburn/sg-freebsd.c b/libburn/trunk/libburn/sg-freebsd.c index 6ca26f2f..8f547fbe 100644 --- a/libburn/trunk/libburn/sg-freebsd.c +++ b/libburn/trunk/libburn/sg-freebsd.c @@ -441,6 +441,11 @@ static void enumerate_common(char *fname, int bus_no, int host_no, struct burn_drive *t; struct burn_drive out; + /* Initialize pointers to managed memory */ + out.devname = NULL; + out.idata = NULL; + out.mdata = NULL; + /* ts A60923 */ out.bus_no = bus_no; out.host = host_no; @@ -449,6 +454,8 @@ static void enumerate_common(char *fname, int bus_no, int host_no, out.lun = lun_no; out.devname = strdup(fname); + if (out.devname == NULL) + goto could_not_allocate; out.cam = NULL; out.lock_fd = -1; @@ -493,9 +500,19 @@ static void enumerate_common(char *fname, int bus_no, int host_no, out.idata->valid = 0; out.mdata = calloc(1, sizeof(struct scsi_mode_data)); if (out.idata == NULL || out.mdata == NULL) { +could_not_allocate:; libdax_msgs_submit(libdax_messenger, -1, 0x00020108, LIBDAX_MSGS_SEV_FATAL, LIBDAX_MSGS_PRIO_HIGH, "Could not allocate new drive object", 0, 0); + if (out.devname != NULL) + free(out.devname); + out.devname = NULL; + if (out.idata != NULL) + free(out.idata); + out.idata = NULL; + if (out.mdata != NULL) + free(out.mdata); + out.mdata = NULL; return; } out.mdata->p2a_valid = 0;