From d090fb3ae5802aa0b87a15baaa79722b5534071b Mon Sep 17 00:00:00 2001 From: Tobias Stoeckmann Date: Thu, 24 Oct 2024 21:07:44 +0200 Subject: [PATCH] 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 --- libkmod/libkmod-module.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/libkmod/libkmod-module.c b/libkmod/libkmod-module.c index b410cc5..d79df4d 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);