From 3d56716d362d6a827c5f81029ac64c71b56a2f5c Mon Sep 17 00:00:00 2001 From: Rob Landley Date: Thu, 9 Oct 2014 13:43:32 -0500 Subject: Various bugfixes (mostly resource leaks) from Ashwini Sharma's static analysis, plus occasional tweak by me while reviewing them. --- toys/other/ifconfig.c | 2 +- toys/other/insmod.c | 10 +++++++--- toys/other/losetup.c | 2 +- 3 files changed, 9 insertions(+), 5 deletions(-) (limited to 'toys/other') diff --git a/toys/other/ifconfig.c b/toys/other/ifconfig.c index f5d4215e..4d5c74d0 100644 --- a/toys/other/ifconfig.c +++ b/toys/other/ifconfig.c @@ -6,7 +6,7 @@ * * Not in SUSv4. -USE_IFCONFIG(NEWTOY(ifconfig, "?a", TOYFLAG_BIN)) +USE_IFCONFIG(NEWTOY(ifconfig, "^?a", TOYFLAG_BIN)) config IFCONFIG bool "ifconfig" diff --git a/toys/other/insmod.c b/toys/other/insmod.c index 8aa959a9..81721a31 100644 --- a/toys/other/insmod.c +++ b/toys/other/insmod.c @@ -22,7 +22,7 @@ void insmod_main(void) { char * buf = NULL; int len, res, i; - int fd = xopen(toys.optargs[0], O_RDONLY); + int fd = xopen(*toys.optargs, O_RDONLY); len = fdlength(fd); buf = xmalloc(len); @@ -30,13 +30,17 @@ void insmod_main(void) i = 1; while(toys.optargs[i] && - strlen(toybuf) + strlen(toys.optargs[i]) + 2 < sizeof(toybuf)) { + strlen(toybuf) + strlen(toys.optargs[i]) + 2 < sizeof(toybuf)) + { strcat(toybuf, toys.optargs[i++]); strcat(toybuf, " "); } res = init_module(buf, len, toybuf); - if (CFG_TOYBOX_FREE && buf != toybuf) free(buf); + if (CFG_TOYBOX_FREE) { + if (buf != toybuf) free(buf); + close(fd); + } if (res) perror_exit("failed to load %s", toys.optargs[0]); } diff --git a/toys/other/losetup.c b/toys/other/losetup.c index e96a125d..e3094ef0 100644 --- a/toys/other/losetup.c +++ b/toys/other/losetup.c @@ -86,7 +86,7 @@ static void loopback_setup(char *device, char *file) // Stat the loop device to see if there's a current association. memset(loop, 0, sizeof(struct loop_info64)); if (-1 == lfd || ioctl(lfd, LOOP_GET_STATUS64, loop)) { - if (errno == ENXIO && (flags & (FLAG_a|FLAG_j))) return; + if (errno == ENXIO && (flags & (FLAG_a|FLAG_j))) goto done; if (errno != ENXIO || !file) { perror_msg("%s", device ? device : "-f"); goto done; -- cgit v1.2.3