From 3b1de7b86df2587c1a81c45748f385fefdc10731 Mon Sep 17 00:00:00 2001 From: Philippe Guibert Date: Thu, 16 Apr 2020 15:18:24 +0200 Subject: [PATCH] zebra: do not free iptable context, once created This commit avoids freeing the iptable context, once created. the case where there is an error when reading zapi stream simply needs to free the zpi context. Fixes: ("8b5c4dce07e6 zebra: fix iptable memleak, fix free funcs") Signed-off-by: Philippe Guibert --- zebra/zebra_pbr.c | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/zebra/zebra_pbr.c b/zebra/zebra_pbr.c index c5a7795273..1bc8d893bc 100644 --- a/zebra/zebra_pbr.c +++ b/zebra/zebra_pbr.c @@ -336,14 +336,20 @@ bool zebra_pbr_ipset_entry_hash_equal(const void *arg1, const void *arg2) return true; } -void zebra_pbr_iptable_free(void *arg) +/* this function gives option to flush plugin memory contexts + * with all parameter. set it to true to flush all + * set it to false to flush only passed arg argument + */ +static void _zebra_pbr_iptable_free_all(void *arg, bool all) { struct zebra_pbr_iptable *iptable; struct listnode *node, *nnode; char *name; iptable = (struct zebra_pbr_iptable *)arg; - hook_call(zebra_pbr_iptable_update, 0, iptable); + + if (all) + hook_call(zebra_pbr_iptable_update, 0, iptable); if (iptable->interface_name_list) { for (ALL_LIST_ELEMENTS(iptable->interface_name_list, node, @@ -356,6 +362,11 @@ void zebra_pbr_iptable_free(void *arg) XFREE(MTYPE_TMP, iptable); } +void zebra_pbr_iptable_free(void *arg) +{ + _zebra_pbr_iptable_free_all(arg, false); +} + uint32_t zebra_pbr_iptable_hash_key(const void *arg) { const struct zebra_pbr_iptable *iptable = arg; @@ -529,7 +540,7 @@ static void zebra_pbr_cleanup_iptable(struct hash_bucket *b, void *data) if (iptable->sock == *sock) { if (hash_release(zrouter.iptable_hash, iptable)) - zebra_pbr_iptable_free(iptable); + _zebra_pbr_iptable_free_all(iptable, true); else hook_call(zebra_pbr_iptable_update, 0, iptable); } -- 2.39.5