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.
This commit is contained in:
Ilia Shipitsin 2024-12-03 17:10:21 +01:00 committed by Willy Tarreau
parent 1f63a53955
commit abee546850

View File

@ -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)