]> git.puffer.fish Git - mirror/frr.git/commitdiff
bgpd: fix bgp_pbr_match_entry memory leak
authorLouis Scalbert <louis.scalbert@6wind.com>
Fri, 11 Apr 2025 15:11:55 +0000 (17:11 +0200)
committerLouis Scalbert <louis.scalbert@6wind.com>
Mon, 14 Apr 2025 11:09:34 +0000 (13:09 +0200)
> ==238132==ERROR: LeakSanitizer: detected memory leaks
>
> Direct leak of 160 byte(s) in 1 object(s) allocated from:
>     #0 0x7fd79f0b4a57 in __interceptor_calloc ../../../../src/libsanitizer/asan/asan_malloc_linux.cpp:154
>     #1 0x7fd79ea6f8dd in qcalloc lib/memory.c:105
>     #2 0x5586b26995f9 in bgp_pbr_match_entry_alloc_intern bgpd/bgp_pbr.c:1155
>     #3 0x7fd79ea17d79 in hash_get lib/hash.c:147
>     #4 0x5586b26a551d in bgp_pbr_policyroute_add_to_zebra_unit bgpd/bgp_pbr.c:2522
>     #5 0x5586b26a6436 in bgp_pbr_policyroute_add_to_zebra bgpd/bgp_pbr.c:2672
>     #6 0x5586b26a8089 in bgp_pbr_handle_entry bgpd/bgp_pbr.c:2876
>     #7 0x5586b26a8912 in bgp_pbr_update_entry bgpd/bgp_pbr.c:2939
>     #8 0x5586b2829472 in bgp_zebra_announce bgpd/bgp_zebra.c:1618
>     #9 0x5586b282ab4b in bgp_zebra_announce_table bgpd/bgp_zebra.c:1766
>     #10 0x5586b2824b99 in bgp_zebra_tm_connect bgpd/bgp_zebra.c:1091
>     #11 0x7fd79eb7798e in event_call lib/event.c:2011
>     #12 0x7fd79ea42ff1 in frr_run lib/libfrr.c:1216
>     #13 0x5586b2503a15 in main bgpd/bgp_main.c:545
>     #14 0x7fd79e429d8f in __libc_start_call_main ../sysdeps/nptl/libc_start_call_main.h:58

Fixes: d114b0d739 ("bgpd: inject policy route entry from bgp into zebra pbr entries.")
Signed-off-by: Louis Scalbert <louis.scalbert@6wind.com>
bgpd/bgp_pbr.c

index be4c4741fd31f9e1d6fce52b4ccad9de0239ce13..ec4f19cccf19a4c5206bfc664dad41c28bc49370 100644 (file)
@@ -965,7 +965,12 @@ int bgp_pbr_build_and_validate_entry(const struct prefix *p,
        return 0;
 }
 
-static void bgp_pbr_match_entry_free(void *arg)
+static void bgp_pbr_match_entry_free(struct bgp_pbr_match_entry *bpme)
+{
+       XFREE(MTYPE_PBR_MATCH_ENTRY, bpme);
+}
+
+static void bgp_pbr_match_entry_hash_free(void *arg)
 {
        struct bgp_pbr_match_entry *bpme;
 
@@ -976,7 +981,7 @@ static void bgp_pbr_match_entry_free(void *arg)
                bpme->installed = false;
                bpme->backpointer = NULL;
        }
-       XFREE(MTYPE_PBR_MATCH_ENTRY, bpme);
+       bgp_pbr_match_entry_free(bpme);
 }
 
 static void bgp_pbr_match_free(void *arg)
@@ -985,7 +990,7 @@ static void bgp_pbr_match_free(void *arg)
 
        bpm = (struct bgp_pbr_match *)arg;
 
-       hash_clean(bpm->entry_hash, bgp_pbr_match_entry_free);
+       hash_clean(bpm->entry_hash, bgp_pbr_match_entry_hash_free);
 
        if (hashcount(bpm->entry_hash) == 0) {
                /* delete iptable entry first */
@@ -1685,6 +1690,7 @@ static void bgp_pbr_flush_entry(struct bgp *bgp, struct bgp_pbr_action *bpa,
                }
        }
        hash_release(bpm->entry_hash, bpme);
+       bgp_pbr_match_entry_free(bpme);
        if (hashcount(bpm->entry_hash) == 0) {
                /* delete iptable entry first */
                /* then delete ipset match */