summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorChristian Marangi2024-01-21 23:49:44 +0000
committerChristian Marangi2024-01-21 23:52:21 +0000
commit202d7c05029a43f5665cd81355d8abdfdec2bb2d (patch)
treee57c15362355e8ae3df8b10ee3d2c6e3c17f0764
parentb2f6da671f7c747fe9e65080c7c012b945cacb50 (diff)
downloadubox-202d7c05029a43f5665cd81355d8abdfdec2bb2d.tar.gz
kmodloader: fix memory leak in print_modinfo
Fix memory leak in print_modinfo reported by Coverity Report. It seems there is a logic error and duplicated string in print_modinfo is never freed. On top of this if the while loop terminates early the just allocated duplicated string is also never freed. Rework the function to correctly free the duplicated string. Fix CID 1586644: Resource leaks (RESOURCE_LEAK). Signed-off-by: Christian Marangi <ansuelsmth@gmail.com>
-rw-r--r--kmodloader.c9
1 files changed, 6 insertions, 3 deletions
diff --git a/kmodloader.c b/kmodloader.c
index 2cb6088..43105b3 100644
--- a/kmodloader.c
+++ b/kmodloader.c
@@ -649,8 +649,11 @@ static int print_modinfo(const struct module *m)
printf("%s:\t%s\n", dup, sep);
} else {
sep2 = strstr(sep, ":");
- if (!sep2)
+ if (!sep2) {
+ free(dup);
break;
+ }
+
pname = strndup(sep, sep2 - sep);
sep2++;
pdata = strdup(sep2);
@@ -673,10 +676,10 @@ static int print_modinfo(const struct module *m)
else
p->desc = pdata;
}
+
+ free(dup);
next_string:
strings = &sep[strlen(sep)];
- if (dup)
- free(dup);
}
list_for_each_entry(p, &params, list) {