aboutsummaryrefslogtreecommitdiff
path: root/toys/other/insmod.c
diff options
context:
space:
mode:
authorRob Landley <rob@landley.net>2014-10-09 13:43:32 -0500
committerRob Landley <rob@landley.net>2014-10-09 13:43:32 -0500
commit3d56716d362d6a827c5f81029ac64c71b56a2f5c (patch)
tree93377ffa6621214916c82b0985483e4d13822336 /toys/other/insmod.c
parent7196d758a0728bd43451f869eb85528b6cd20bea (diff)
downloadtoybox-3d56716d362d6a827c5f81029ac64c71b56a2f5c.tar.gz
Various bugfixes (mostly resource leaks) from Ashwini Sharma's static analysis, plus occasional tweak by me while reviewing them.
Diffstat (limited to 'toys/other/insmod.c')
-rw-r--r--toys/other/insmod.c10
1 files changed, 7 insertions, 3 deletions
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]);
}