From: Tobias Stoeckmann Date: Thu, 24 Oct 2024 19:07:44 +0000 (+0200) Subject: libkmod: Clean up all dependencies on error path X-Git-Tag: v34~155 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=d090fb3ae5802aa0b87a15baaa79722b5534071b;p=thirdparty%2Fkmod.git libkmod: Clean up all dependencies on error path If kmod_module_parse_depline runs out of memory, it is possible that not all dependency modules are unlinked. Signed-off-by: Tobias Stoeckmann Reviewed-by: Emil Velikov Link: https://github.com/kmod-project/kmod/pull/211 Signed-off-by: Lucas De Marchi --- diff --git a/libkmod/libkmod-module.c b/libkmod/libkmod-module.c index b410cc5e..d79df4d6 100644 --- a/libkmod/libkmod-module.c +++ b/libkmod/libkmod-module.c @@ -146,6 +146,7 @@ void kmod_module_parse_depline(struct kmod_module *mod, char *line) p++; for (p = strtok_r(p, " \t", &saveptr); p != NULL; p = strtok_r(NULL, " \t", &saveptr)) { + struct kmod_list *l_new; struct kmod_module *depmod = NULL; const char *path; int err; @@ -164,7 +165,12 @@ void kmod_module_parse_depline(struct kmod_module *mod, char *line) DBG(ctx, "add dep: %s\n", path); - list = kmod_list_prepend(list, depmod); + l_new = kmod_list_prepend(list, depmod); + if (l_new == NULL) { + ERR(ctx, "could not add dependency for %s\n", mod->name); + goto fail; + } + list = l_new; } DBG(ctx, "%zu dependencies for %s\n", n, mod->name);