diff options
author | Rafael Zalamena <rzalamena@opensourcerouting.org> | 2019-10-15 04:29:19 +0200 |
---|---|---|
committer | Rafael Zalamena <rzalamena@opensourcerouting.org> | 2020-02-04 18:05:43 +0100 |
commit | 54a35ff48b600cd59b715b6e5aea4e69de1b995f (patch) | |
tree | 75bb1d0132d4d4e2f865529a3c49200c692c557b /lib/routemap_northbound.c | |
parent | *: fix route map integration (diff) | |
download | frr-54a35ff48b600cd59b715b6e5aea4e69de1b995f.tar.xz frr-54a35ff48b600cd59b715b6e5aea4e69de1b995f.zip |
lib: fix route map northbound memory leak
Keep a list of hook contexts used by northbound so we don't lose the
pointer when free()ing the route map index entry data.
Signed-off-by: Rafael Zalamena <rzalamena@opensourcerouting.org>
Diffstat (limited to 'lib/routemap_northbound.c')
-rw-r--r-- | lib/routemap_northbound.c | 39 |
1 files changed, 30 insertions, 9 deletions
diff --git a/lib/routemap_northbound.c b/lib/routemap_northbound.c index b9ac01e86..3173a708e 100644 --- a/lib/routemap_northbound.c +++ b/lib/routemap_northbound.c @@ -75,6 +75,30 @@ int lib_route_map_entry_set_destroy(enum nb_event event, } /* + * Auxiliary hook context list manipulation functions. + */ +struct routemap_hook_context * +routemap_hook_context_insert(struct route_map_index *rmi) +{ + struct routemap_hook_context *rhc; + + rhc = XCALLOC(MTYPE_TMP, sizeof(*rhc)); + rhc->rhc_rmi = rmi; + TAILQ_INSERT_TAIL(&rmi->rhclist, rhc, rhc_entry); + + return rhc; +} + +void +routemap_hook_context_free(struct routemap_hook_context *rhc) +{ + struct route_map_index *rmi = rhc->rhc_rmi; + + TAILQ_REMOVE(&rmi->rhclist, rhc, rhc_entry); + XFREE(MTYPE_TMP, rhc); +} + +/* * XPath: /frr-route-map:lib/route-map */ static int lib_route_map_create(enum nb_event event, @@ -436,20 +460,17 @@ lib_route_map_entry_match_condition_create(enum nb_event event, union nb_resource *resource) { struct routemap_hook_context *rhc; + struct route_map_index *rmi; switch (event) { case NB_EV_VALIDATE: - /* NOTHING */ - break; case NB_EV_PREPARE: - resource->ptr = XCALLOC(MTYPE_TMP, sizeof(*rhc)); - break; case NB_EV_ABORT: - XFREE(MTYPE_TMP, resource->ptr); + /* NOTHING */ break; case NB_EV_APPLY: - rhc = resource->ptr; - rhc->rhc_rmi = nb_running_get_entry(dnode, NULL, true); + rmi = nb_running_get_entry(dnode, NULL, true); + rhc = routemap_hook_context_insert(rmi); nb_running_set_entry(dnode, rhc); break; } @@ -469,7 +490,7 @@ lib_route_map_entry_match_condition_destroy(enum nb_event event, rv = lib_route_map_entry_match_destroy(event, dnode); rhc = nb_running_unset_entry(dnode); - XFREE(MTYPE_TMP, rhc); + routemap_hook_context_free(rhc); return rv; } @@ -893,7 +914,7 @@ static int lib_route_map_entry_set_action_destroy(enum nb_event event, rv = lib_route_map_entry_set_destroy(event, dnode); rhc = nb_running_unset_entry(dnode); - XFREE(MTYPE_TMP, rhc); + routemap_hook_context_free(rhc); return rv; } |