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/insmod.c | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) (limited to 'toys/other/insmod.c') 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]); } -- cgit v1.2.3