From: Tobias Stoeckmann Date: Wed, 6 Nov 2024 16:50:27 +0000 (+0100) Subject: depmod: Release memory on error path X-Git-Tag: v34~96 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=5a5b4c545c2789665370eadb9e8b160502d08941;p=thirdparty%2Fkmod.git depmod: Release memory on error path Check malloc return value and clean up resources if allocation fails. Signed-off-by: Tobias Stoeckmann Link: https://github.com/kmod-project/kmod/pull/228 Signed-off-by: Lucas De Marchi --- diff --git a/tools/depmod.c b/tools/depmod.c index dc4b8a2f..a3b75ad8 100644 --- a/tools/depmod.c +++ b/tools/depmod.c @@ -1802,7 +1802,7 @@ static int depmod_report_one_cycle(struct depmod *depmod, struct vertex *vertex, int i; int n; struct vertex *v; - int rc; + int rc = 0; array_init(&reverse, 3); @@ -1820,6 +1820,10 @@ static int depmod_report_one_cycle(struct depmod *depmod, struct vertex *vertex, sz += vertex->mod->modnamesz - 1; buf = malloc(sz + n * strlen(sep) + 1); + if (buf == NULL) { + rc = -ENOMEM; + goto out; + } sz = 0; for (i = reverse.count - 1; i >= 0; i--) { @@ -1839,9 +1843,10 @@ static int depmod_report_one_cycle(struct depmod *depmod, struct vertex *vertex, ERR("Cycle detected: %s\n", buf); free(buf); +out: array_free_array(&reverse); - return 0; + return rc; } static int depmod_report_cycles_from_root(struct depmod *depmod, struct mod *root_mod,