]> git.ipfire.org Git - thirdparty/kmod.git/commitdiff
depmod: Release memory on error paths
authorTobias Stoeckmann <tobias@stoeckmann.org>
Tue, 5 Nov 2024 16:58:15 +0000 (17:58 +0100)
committerLucas De Marchi <lucas.de.marchi@gmail.com>
Fri, 15 Nov 2024 18:59:45 +0000 (12:59 -0600)
If a list node could not be added, release already allocated data which
was supposed to end up in list.

Signed-off-by: Tobias Stoeckmann <tobias@stoeckmann.org>
Link: https://github.com/kmod-project/kmod/pull/228
Signed-off-by: Lucas De Marchi <lucas.de.marchi@gmail.com>
tools/depmod.c

index 999b5b5a4e80788ded72740fdc39e5e868bf3cdd..dc4b8a2f149b01706e38e70f99ab46ac44289ec4 100644 (file)
@@ -1867,6 +1867,7 @@ static int depmod_report_cycles_from_root(struct depmod *depmod, struct mod *roo
        l = kmod_list_append(free_list, root);
        if (l == NULL) {
                ERR("No memory to report cycles\n");
+               free(root);
                goto out;
        }
        free_list = l;
@@ -1922,6 +1923,7 @@ static int depmod_report_cycles_from_root(struct depmod *depmod, struct mod *roo
                        l = kmod_list_append(free_list, v);
                        if (l == NULL) {
                                ERR("No memory to report cycles\n");
+                               free(v);
                                goto out;
                        }
                        free_list = l;