From ea3ce9a1a5798511fbbe7905e9b2228f1954ae01 Mon Sep 17 00:00:00 2001 From: Donald Sharp Date: Fri, 26 May 2017 11:54:07 -0400 Subject: [PATCH] bgpd: On cleanup make sure pointers exist Test cases create fake bgp structure that is passed to cleanup. The new evpn code assumed ( and probably rightly so) that if the bgp structure was created it actually initialized all useful data structures. Just make the evpn cleanup functions be smart about attempting to free memory never allocated. Signed-off-by: Donald Sharp --- bgpd/bgp_evpn.c | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/bgpd/bgp_evpn.c b/bgpd/bgp_evpn.c index 77dc2f2bc7..d012952784 100644 --- a/bgpd/bgp_evpn.c +++ b/bgpd/bgp_evpn.c @@ -2830,12 +2830,15 @@ bgp_evpn_cleanup_on_disable (struct bgp *bgp) void bgp_evpn_cleanup (struct bgp *bgp) { - hash_iterate (bgp->vnihash, - (void (*) (struct hash_backet *, void *)) - free_vni_entry, bgp); - hash_free (bgp->import_rt_hash); + if (bgp->vnihash) + hash_iterate (bgp->vnihash, + (void (*) (struct hash_backet *, void *)) + free_vni_entry, bgp); + if (bgp->import_rt_hash) + hash_free (bgp->import_rt_hash); bgp->import_rt_hash = NULL; - hash_free (bgp->vnihash); + if (bgp->vnihash) + hash_free (bgp->vnihash); bgp->vnihash = NULL; bf_free (bgp->rd_idspace); } -- 2.39.5