]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
BUG/MEDIUM: deviceatlas: fix resource leaks on init error paths
authorDavid Carlier <dcarlier@deviceatlas.com>
Sat, 14 Feb 2026 13:23:57 +0000 (13:23 +0000)
committerWilly Tarreau <w@1wt.eu>
Sat, 14 Feb 2026 13:47:22 +0000 (14:47 +0100)
When da_atlas_compile() or da_atlas_open() failed in init_deviceatlas(),
atlasimgptr was leaked and da_fini() was never called. Also add a NULL
check on strdup() for the default cookie name with proper cleanup of
the atlas and image pointer on failure.

This should be backported to lower branches.

addons/deviceatlas/da.c

index 3b157667832f172cbb5d205c31af4674399c1c5f..d40041a6a0cc3cef80aa740cc4c5c3b18bcd7e04 100644 (file)
@@ -190,6 +190,8 @@ static int init_deviceatlas(void)
                if (status != DA_OK) {
                        ha_alert("deviceatlas : '%s' json file is invalid.\n",
                                 global_deviceatlas.jsonpath);
+                       free(global_deviceatlas.atlasimgptr);
+                       da_fini();
                        err_code |= ERR_ALERT | ERR_FATAL;
                        goto out;
                }
@@ -199,6 +201,8 @@ static int init_deviceatlas(void)
 
                if (status != DA_OK) {
                        ha_alert("deviceatlas : data could not be compiled.\n");
+                       free(global_deviceatlas.atlasimgptr);
+                       da_fini();
                        err_code |= ERR_ALERT | ERR_FATAL;
                        goto out;
                }
@@ -207,6 +211,14 @@ static int init_deviceatlas(void)
 
                if (global_deviceatlas.cookiename == 0) {
                        global_deviceatlas.cookiename = strdup(DA_COOKIENAME_DEFAULT);
+                       if (unlikely(global_deviceatlas.cookiename == NULL)) {
+                               ha_alert("deviceatlas : out of memory.\n");
+                               da_atlas_close(&global_deviceatlas.atlas);
+                               free(global_deviceatlas.atlasimgptr);
+                               da_fini();
+                               err_code |= ERR_ALERT | ERR_FATAL;
+                               goto out;
+                       }
                        global_deviceatlas.cookienamelen = strlen(global_deviceatlas.cookiename);
                }