From: Ilia Shipitsin Date: Tue, 3 Dec 2024 16:10:21 +0000 (+0100) Subject: BUG/MINOR: namespace: handle a possible strdup() failure X-Git-Tag: v3.2-dev1~14 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=abee5468509a77537015a7e5dc37268d4d564e03;p=thirdparty%2Fhaproxy.git BUG/MINOR: namespace: handle a possible strdup() failure This defect was found by the coccinelle script "unchecked-strdup.cocci". It can be backported to all supported branches. --- diff --git a/src/namespace.c b/src/namespace.c index 9cc85a3847..38464bd4cf 100644 --- a/src/namespace.c +++ b/src/namespace.c @@ -89,13 +89,23 @@ struct netns_entry* netns_store_insert(const char *ns_name) entry = calloc(1, sizeof(*entry)); if (!entry) - goto out; + goto err_close_fd; entry->fd = fd; entry->node.key = strdup(ns_name); + if (!entry->node.key) + goto err_free_entry; + entry->name_len = strlen(ns_name); ebis_insert(&namespace_tree_root, &entry->node); out: return entry; + +/* free all allocated stuff and return entry */ +err_free_entry: + ha_free(&entry); +err_close_fd: + close(fd); + return entry; } const struct netns_entry* netns_store_lookup(const char *ns_name, size_t ns_name_len)