From 7eb9068901571e0dcd23ce887bdc3e018683f298 Mon Sep 17 00:00:00 2001 From: Donald Sharp Date: Thu, 16 Mar 2017 15:56:54 -0400 Subject: [PATCH] pimd: Cleanup ref counting pim_jp_agg list should not ref count pim_upstream as that the deletion of pim_upstream deletion should remove the pim_upstream from the j/p agg list. Cleanup a memory leag of jag Make comparison of js cleaner in add_group Move THREAD_OFF to before the neighbor find. Signed-off-by: Donald Sharp --- pimd/pim_jp_agg.c | 13 ++++++------- pimd/pim_upstream.c | 10 ++++------ 2 files changed, 10 insertions(+), 13 deletions(-) diff --git a/pimd/pim_jp_agg.c b/pimd/pim_jp_agg.c index eb13ebf31b..29faace322 100644 --- a/pimd/pim_jp_agg.c +++ b/pimd/pim_jp_agg.c @@ -51,9 +51,6 @@ pim_jp_agg_src_free (struct pim_jp_sources *js) * pick this shit back up when the * nbr comes back alive */ - - up = pim_upstream_del (up, __PRETTY_FUNCTION__); - if (up) join_timer_start(js->up); XFREE (MTYPE_PIM_JP_AGG_SOURCE, js); @@ -113,8 +110,8 @@ pim_jp_agg_clear_group (struct list *group) { for (ALL_LIST_ELEMENTS(jag->sources, snode, snnode, js)) { - pim_upstream_del (js->up, __PRETTY_FUNCTION__); listnode_delete(jag->sources, js); + js->up = NULL; XFREE(MTYPE_PIM_JP_AGG_SOURCE, js); } jag->sources = NULL; @@ -171,7 +168,7 @@ pim_jp_agg_remove_group (struct list *group, struct pim_upstream *up) if (js) { - pim_upstream_del (up, __PRETTY_FUNCTION__); + js->up = NULL; listnode_delete(jag->sources, js); XFREE(MTYPE_PIM_JP_AGG_SOURCE, js); } @@ -179,8 +176,11 @@ pim_jp_agg_remove_group (struct list *group, struct pim_upstream *up) if (jag->sources->count == 0) { list_delete(jag->sources); + jag->sources = NULL; listnode_delete(group, jag); + XFREE(MTYPE_PIM_JP_AGG_GROUP, jag); } + } int @@ -275,14 +275,13 @@ pim_jp_agg_add_group (struct list *group, struct pim_upstream *up, bool is_join) for (ALL_LIST_ELEMENTS(jag->sources, node, nnode, js)) { - if (js->up->sg.src.s_addr == up->sg.src.s_addr) + if (js->up == up) break; } if (!js) { js = XCALLOC(MTYPE_PIM_JP_AGG_SOURCE, sizeof (struct pim_jp_sources)); - pim_upstream_ref (up, 0); js->up = up; js->is_join = is_join; listnode_add_sort (jag->sources, js); diff --git a/pimd/pim_upstream.c b/pimd/pim_upstream.c index 31b623280b..759c955412 100644 --- a/pimd/pim_upstream.c +++ b/pimd/pim_upstream.c @@ -142,7 +142,6 @@ pim_upstream_find_parent (struct pim_upstream *child) void pim_upstream_free(struct pim_upstream *up) { - memset (up, 0, sizeof (struct pim_upstream)); XFREE(MTYPE_PIM_UPSTREAM, up); up = NULL; } @@ -162,15 +161,13 @@ pim_upstream_del(struct pim_upstream *up, const char *name) struct prefix nht_p; if (PIM_DEBUG_TRACE) - zlog_debug ("%s(%s): Delete %s ref count: %d", - __PRETTY_FUNCTION__, name, up->sg_str, up->ref_count); + zlog_debug ("%s(%s): Delete %s ref count: %d, flags: %d (Pre decrement)", + __PRETTY_FUNCTION__, name, up->sg_str, up->ref_count, up->flags); --up->ref_count; if (up->ref_count >= 1) return up; - else if (up->ref_count < 0) - return NULL; THREAD_OFF(up->t_ka_timer); THREAD_OFF(up->t_rs_timer); @@ -291,13 +288,14 @@ static void join_timer_stop(struct pim_upstream *up) { struct pim_neighbor *nbr; + THREAD_OFF (up->t_join_timer); + nbr = pim_neighbor_find (up->rpf.source_nexthop.interface, up->rpf.rpf_addr.u.prefix4); if (nbr) pim_jp_agg_remove_group (nbr->upstream_jp_agg, up); - THREAD_OFF (up->t_join_timer); pim_jp_agg_upstream_verification (up, false); } -- 2.39.5