From: Tobias Stoeckmann Date: Tue, 10 Sep 2024 16:18:48 +0000 (+0200) Subject: depmod: Handle malloc failure in index_create X-Git-Tag: v34~327 X-Git-Url: http://git.ipfire.org/gitweb/gitweb.cgi?a=commitdiff_plain;h=7c624d3088880ad3c5845169ce3e10a2f9d9ccbd;p=thirdparty%2Fkmod.git depmod: Handle malloc failure in index_create Callers already check error return value, so actually return one in case of failure. Signed-off-by: Tobias Stoeckmann Link: https://github.com/kmod-project/kmod/pull/130 Signed-off-by: Lucas De Marchi --- diff --git a/tools/depmod.c b/tools/depmod.c index fde91d67..90509d32 100644 --- a/tools/depmod.c +++ b/tools/depmod.c @@ -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;