]> git.ipfire.org Git - thirdparty/lldpd.git/commitdiff
daemon/interfaces-bsd: free req in ifbsd_check_bridge
authorVincent Bernat <vincent@bernat.ch>
Sat, 9 May 2026 13:01:50 +0000 (15:01 +0200)
committerVincent Bernat <vincent@bernat.ch>
Sat, 9 May 2026 13:26:12 +0000 (15:26 +0200)
The function allocated req via `realloc()` and never freed it, leaking
on every interface refresh. Add a goto end pattern so all exit paths
release it.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
src/daemon/interfaces-bsd.c

index a8248fe96003ced1ca9c04c8458116adabceecea..7761a643e11e696d30aa632bed9b3ff168d14092 100644 (file)
@@ -75,11 +75,15 @@ ifbsd_check_bridge(struct lldpd *cfg, struct interfaces_device_list *interfaces,
        struct ifbifconf bifc = {};
 
 retry_alloc:
-       if ((req = realloc(req, ifbic_len)) == NULL) {
-               log_warn("interfaces", "unable to allocate memory to query bridge %s",
-                   master->name);
-               free(bifc.ifbic_req);
-               return;
+       {
+               struct ifbreq *new_req = realloc(req, ifbic_len);
+               if (new_req == NULL) {
+                       log_warn("interfaces",
+                           "unable to allocate memory to query bridge %s",
+                                       master->name);
+                       goto end;
+               }
+               req = new_req;
        }
        bifc.ifbic_len = ifbic_len;
        bifc.ifbic_req = req;
@@ -93,13 +97,13 @@ retry_alloc:
        strlcpy(ifd.ifd_name, master->name, sizeof(ifd.ifd_name));
        if (ioctl(cfg->g_sock, SIOCGDRVSPEC, (caddr_t)&ifd) < 0) {
                log_debug("interfaces", "%s is not a bridge", master->name);
-               return;
+               goto end;
        }
 #elif defined HOST_OS_OPENBSD
        strlcpy(bifc.ifbic_name, master->name, sizeof(bifc.ifbic_name));
        if (ioctl(cfg->g_sock, SIOCBRDGIFS, (caddr_t)&bifc) < 0) {
                log_debug("interfaces", "%s is not a bridge", master->name);
-               return;
+               goto end;
        }
 #else
 #  error Unsupported OS
@@ -122,6 +126,8 @@ retry_alloc:
                slave->upper = master;
        }
        master->type |= IFACE_BRIDGE_T;
+end:
+       free(req);
 }
 
 static void