]> git.ipfire.org Git - thirdparty/kmod.git/commitdiff
depmod: Handle malloc failure in index_create
authorTobias Stoeckmann <tobias@stoeckmann.org>
Tue, 10 Sep 2024 16:18:48 +0000 (18:18 +0200)
committerLucas De Marchi <lucas.de.marchi@gmail.com>
Tue, 17 Sep 2024 03:40:26 +0000 (22:40 -0500)
Callers already check error return value, so actually return one in case
of failure.

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

index fde91d67fff1a1386e94e6e3575909dc72a7003d..90509d329117ebe77a00e90b9209ac62b9474a95 100644 (file)
@@ -156,8 +156,16 @@ static struct index_node *index_create(void)
 {
        struct index_node *node;
 
-       node = NOFAIL(calloc(1, sizeof(struct index_node)));
-       node->prefix = NOFAIL(strdup(""));
+       node = calloc(1, sizeof(struct index_node));
+       if (node == NULL)
+               return NULL;
+
+       node->prefix = strdup("");
+       if (node->prefix == NULL) {
+               free(node);
+               return NULL;
+       }
+
        node->first = INDEX_CHILDMAX;
 
        return node;