From a93b407811f348e7d5f0c631c6277f8814f050c4 Mon Sep 17 00:00:00 2001 From: Ilia Shipitsin Date: Wed, 13 May 2026 18:12:02 +0200 Subject: [PATCH] MINOR: addons/51degrees: handle memory allocation failures Found via cppcheck --force --enable=all --output-file=haproxy.log : addons/51degrees/51d.c:130:3: warning: If memory allocation fails, then there is a possible null pointer dereference: name [nullPointerOutOfMemory] addons/51degrees/51d.c:922:4: warning: If memory allocation fails, then there is a possible null pointer dereference: _51d_property_list [nullPointerOutOfMemory] --- addons/51degrees/51d.c | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/addons/51degrees/51d.c b/addons/51degrees/51d.c index be2dc61bd..ad49db1dd 100644 --- a/addons/51degrees/51d.c +++ b/addons/51degrees/51d.c @@ -127,7 +127,16 @@ static int _51d_property_name_list(char **args, int section_type, struct proxy * while (*(args[cur_arg])) { name = calloc(1, sizeof(*name)); + if (!name) { + memprintf(err, "'%s' failed to allocate memory.", args[0]); + return -1; + } name->name = strdup(args[cur_arg]); + if (!name->name) { + free(name); + memprintf(err, "'%s' failed to allocate memory.", args[0]); + return -1; + } LIST_APPEND(&global_51degrees.property_names, &name->list); ++cur_arg; } @@ -928,6 +937,10 @@ static int init_51degrees(void) list_for_each_entry(name, &global_51degrees.property_names, list) ++i; _51d_property_list = calloc(i, sizeof(*_51d_property_list)); + if (!_51d_property_list) { + ha_alert("51Degrees: Failed to allocate property list.\n"); + return (ERR_FATAL | ERR_ALERT); + } i = 0; list_for_each_entry(name, &global_51degrees.property_names, list) -- 2.47.3