From f2c2e5e59c139d1e290dfe93365b0cc879677c6c 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. --- cdrskin/cdrskin_timestamp.h | 2 +- libburn/sg-freebsd.c | 17 +++++++++++++++++ 2 files changed, 18 insertions(+), 1 deletion(-) diff --git a/cdrskin/cdrskin_timestamp.h b/cdrskin/cdrskin_timestamp.h index f74cbb5..d2ed91c 100644 --- a/cdrskin/cdrskin_timestamp.h +++ b/cdrskin/cdrskin_timestamp.h @@ -1 +1 @@ -#define Cdrskin_timestamP "2015.11.02.151241" +#define Cdrskin_timestamP "2015.11.25.093414" diff --git a/libburn/sg-freebsd.c b/libburn/sg-freebsd.c index 6ca26f2..8f547fb 100644 --- a/libburn/sg-freebsd.c +++ b/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;