From 5d0cef584f3d1910fc64f18ec69461e78d5d319f Mon Sep 17 00:00:00 2001 From: Donatas Abraitis Date: Thu, 19 Dec 2024 10:56:52 +0200 Subject: [PATCH] bgpd: Fix memory leak when creating BMP connection with a source interface 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 (cherry picked from commit 7d19cb59cf5b129f61f3c568899343b3f031f9b4) --- bgpd/bgp_bmp.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/bgpd/bgp_bmp.c b/bgpd/bgp_bmp.c index 0ad85c984d8d..785345221e89 100644 --- a/bgpd/bgp_bmp.c +++ b/bgpd/bgp_bmp.c @@ -2392,8 +2392,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)