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 <tobias@stoeckmann.org>
Reviewed-by: Emil Velikov <emil.l.velikov@gmail.com>
Link: https://github.com/kmod-project/kmod/pull/211
Signed-off-by: Lucas De Marchi <lucas.de.marchi@gmail.com>
This commit is contained in:
Tobias Stoeckmann 2024-10-24 21:07:44 +02:00 committed by Lucas De Marchi
parent 6ac1bccfe1
commit d090fb3ae5

View File

@ -146,6 +146,7 @@ void kmod_module_parse_depline(struct kmod_module *mod, char *line)
p++; p++;
for (p = strtok_r(p, " \t", &saveptr); p != NULL; for (p = strtok_r(p, " \t", &saveptr); p != NULL;
p = strtok_r(NULL, " \t", &saveptr)) { p = strtok_r(NULL, " \t", &saveptr)) {
struct kmod_list *l_new;
struct kmod_module *depmod = NULL; struct kmod_module *depmod = NULL;
const char *path; const char *path;
int err; int err;
@ -164,7 +165,12 @@ void kmod_module_parse_depline(struct kmod_module *mod, char *line)
DBG(ctx, "add dep: %s\n", path); 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); DBG(ctx, "%zu dependencies for %s\n", n, mod->name);