From abee5468509a77537015a7e5dc37268d4d564e03 Mon Sep 17 00:00:00 2001 From: Ilia Shipitsin Date: Tue, 3 Dec 2024 17:10:21 +0100 Subject: [PATCH] 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. --- src/namespace.c | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/src/namespace.c b/src/namespace.c index 9cc85a384..38464bd4c 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) -- 2.47.3