]> git.ipfire.org Git - thirdparty/kmod.git/commitdiff
libkmod: Clean up all dependencies on error path
authorTobias Stoeckmann <tobias@stoeckmann.org>
Thu, 24 Oct 2024 19:07:44 +0000 (21:07 +0200)
committerLucas De Marchi <lucas.de.marchi@gmail.com>
Tue, 29 Oct 2024 02:55:10 +0000 (21:55 -0500)
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>
libkmod/libkmod-module.c

index b410cc5e74da49e1bb6482763494db89a4b9231b..d79df4d6c382518ebb89d9e81405e65589611ca4 100644 (file)
@@ -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);