Mercurial > hg > toybox
diff toys/other/insmod.c @ 1518:4bfbd8b96f66 draft
Various bugfixes (mostly resource leaks) from Ashwini Sharma's static analysis, plus occasional tweak by me while reviewing them.
author | Rob Landley <rob@landley.net> |
---|---|
date | Thu, 09 Oct 2014 13:43:32 -0500 |
parents | 786841fdb1e0 |
children | 57f2a26fa92c |
line wrap: on
line diff
--- a/toys/other/insmod.c Thu Oct 09 12:17:36 2014 -0500 +++ b/toys/other/insmod.c Thu Oct 09 13:43:32 2014 -0500 @@ -22,7 +22,7 @@ { 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 @@ 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]); }