]> git.puffer.fish Git - matthieu/frr.git/commitdiff
bgpd: Fix memory leak when creating BMP connection with a source interface
authorDonatas Abraitis <donatas@opensourcerouting.org>
Thu, 19 Dec 2024 08:56:52 +0000 (10:56 +0200)
committerMergify <37929162+mergify[bot]@users.noreply.github.com>
Thu, 19 Dec 2024 21:57:21 +0000 (21:57 +0000)
Testing done with:

```
for x in $(seq 1 100000); do vtysh -c 'conf' -c 'router bgp' -c 'bmp targets test' -c 'bmp connect localhost port 123 min-retry 100 max-retry 100 source-interface lo'; done
```

Signed-off-by: Donatas Abraitis <donatas@opensourcerouting.org>
(cherry picked from commit 7d19cb59cf5b129f61f3c568899343b3f031f9b4)

bgpd/bgp_bmp.c

index 00c9b200c6806525bffcd6c655b0207a5937067a..4e18b21d72bf7ae4c585e3434907a498c7913744 100644 (file)
@@ -2143,8 +2143,11 @@ DEFPY(bmp_connect,
        }
 
        ba = bmp_active_get(bt, hostname, port);
-       if (srcif)
+       if (srcif) {
+               if (ba->ifsrc)
+                       XFREE(MTYPE_TMP, ba->ifsrc);
                ba->ifsrc = XSTRDUP(MTYPE_TMP, srcif);
+       }
        if (min_retry_str)
                ba->minretry = min_retry;
        if (max_retry_str)