Skip to content

Commit

Permalink
Merge pull request #5261 from donaldsharp/pointer_fun
Browse files Browse the repository at this point in the history
Convert some XXX_free lib functions to a double pointer
  • Loading branch information
louberger authored Nov 5, 2019
2 parents ba3afa4 + f609709 commit 3160b7f
Show file tree
Hide file tree
Showing 31 changed files with 109 additions and 96 deletions.
14 changes: 7 additions & 7 deletions bgpd/bgp_debug.c
Original file line number Diff line number Diff line change
Expand Up @@ -209,7 +209,7 @@ static void bgp_debug_list_free(struct list *list)
listnode_delete(list, filter);

if (filter->p)
prefix_free(filter->p);
prefix_free(&filter->p);

if (filter->host)
XFREE(MTYPE_BGP_DEBUG_STR, filter->host);
Expand Down Expand Up @@ -323,7 +323,7 @@ static int bgp_debug_list_remove_entry(struct list *list, const char *host,
} else if (p && filter->p->prefixlen == p->prefixlen
&& prefix_match(filter->p, p)) {
listnode_delete(list, filter);
prefix_free(filter->p);
prefix_free(&filter->p);
XFREE(MTYPE_BGP_DEBUG_FILTER, filter);
return 1;
}
Expand Down Expand Up @@ -1412,7 +1412,7 @@ DEFPY (debug_bgp_update_prefix_afi_safi,

ret = bgp_debug_parse_evpn_prefix(vty, argv, argc, &argv_p);
if (ret != CMD_SUCCESS) {
prefix_free(argv_p);
prefix_free(&argv_p);
return ret;
}

Expand All @@ -1425,7 +1425,7 @@ DEFPY (debug_bgp_update_prefix_afi_safi,
vty_out(vty,
"BGP updates debugging is already enabled for %s\n",
buf);
prefix_free(argv_p);
prefix_free(&argv_p);
return CMD_SUCCESS;
}

Expand All @@ -1438,7 +1438,7 @@ DEFPY (debug_bgp_update_prefix_afi_safi,
vty_out(vty, "BGP updates debugging is on for %s\n", buf);
}

prefix_free(argv_p);
prefix_free(&argv_p);

return CMD_SUCCESS;
}
Expand Down Expand Up @@ -1477,7 +1477,7 @@ DEFPY (no_debug_bgp_update_prefix_afi_safi,

ret = bgp_debug_parse_evpn_prefix(vty, argv, argc, &argv_p);
if (ret != CMD_SUCCESS) {
prefix_free(argv_p);
prefix_free(&argv_p);
return ret;
}

Expand Down Expand Up @@ -1505,7 +1505,7 @@ DEFPY (no_debug_bgp_update_prefix_afi_safi,
vty_out(vty, "BGP updates debugging was not enabled for %s\n",
buf);

prefix_free(argv_p);
prefix_free(&argv_p);

return ret;
}
Expand Down
2 changes: 1 addition & 1 deletion bgpd/bgp_route.c
Original file line number Diff line number Diff line change
Expand Up @@ -10548,7 +10548,7 @@ static int bgp_show_prefix_longer(struct vty *vty, struct bgp *bgp,
}

ret = bgp_show(vty, bgp, afi, safi, type, p, 0);
prefix_free(p);
prefix_free(&p);
return ret;
}

Expand Down
2 changes: 1 addition & 1 deletion bgpd/bgp_zebra.c
Original file line number Diff line number Diff line change
Expand Up @@ -357,7 +357,7 @@ static int bgp_interface_address_delete(ZAPI_CALLBACK_ARGS)
bgp_connected_delete(bgp, ifc);
}

connected_free(ifc);
connected_free(&ifc);

return 0;
}
Expand Down
2 changes: 1 addition & 1 deletion bgpd/bgpd.c
Original file line number Diff line number Diff line change
Expand Up @@ -2586,7 +2586,7 @@ int peer_group_delete(struct peer_group *group)
for (afi = AFI_IP; afi < AFI_MAX; afi++) {
for (ALL_LIST_ELEMENTS(group->listen_range[afi], node, nnode,
prefix)) {
prefix_free(prefix);
prefix_free(&prefix);
}
list_delete(&group->listen_range[afi]);
}
Expand Down
4 changes: 2 additions & 2 deletions bgpd/rfapi/rfapi_import.c
Original file line number Diff line number Diff line change
Expand Up @@ -1512,7 +1512,7 @@ static int rfapiNhlAddNodeRoutes(
}

seen_nexthops =
skiplist_new(0, vnc_prefix_cmp, (void (*)(void *))prefix_free);
skiplist_new(0, vnc_prefix_cmp, prefix_free_lists);

for (bpi = rn->info; bpi; bpi = bpi->next) {

Expand Down Expand Up @@ -4359,7 +4359,7 @@ rfapiImportTableRefAdd(struct bgp *bgp, struct ecommunity *rt_import_list,
it->rt_import_list = ecommunity_dup(rt_import_list);
it->rfg = rfg;
it->monitor_exterior_orphans =
skiplist_new(0, NULL, (void (*)(void *))prefix_free);
skiplist_new(0, NULL, prefix_free_lists);

/*
* fill import route tables from RIBs
Expand Down
12 changes: 4 additions & 8 deletions bgpd/rfapi/vnc_import_bgp.c
Original file line number Diff line number Diff line change
Expand Up @@ -1807,8 +1807,7 @@ static void vnc_import_bgp_exterior_add_route_it(
RFAPI_MONITOR_EXTERIOR(rn)->source =
skiplist_new(
0, NULL,
(void (*)(void *))
prefix_free);
prefix_free_lists);
agg_lock_node(rn); /* for skiplist */
}
agg_lock_node(rn); /* for skiplist entry */
Expand Down Expand Up @@ -2194,8 +2193,7 @@ void vnc_import_bgp_exterior_add_route_interior(
->source) {
RFAPI_MONITOR_EXTERIOR(rn_interior)
->source = skiplist_new(
0, NULL,
(void (*)(void *))prefix_free);
0, NULL, prefix_free_lists);
agg_lock_node(rn_interior);
}
skiplist_insert(
Expand Down Expand Up @@ -2337,8 +2335,7 @@ void vnc_import_bgp_exterior_add_route_interior(
if (!RFAPI_MONITOR_EXTERIOR(rn_interior)->source) {
RFAPI_MONITOR_EXTERIOR(rn_interior)->source =
skiplist_new(
0, NULL,
(void (*)(void *))prefix_free);
0, NULL, prefix_free_lists);
agg_lock_node(rn_interior); /* sl */
}
skiplist_insert(
Expand Down Expand Up @@ -2527,8 +2524,7 @@ void vnc_import_bgp_exterior_del_route_interior(
if (!RFAPI_MONITOR_EXTERIOR(par)->source) {
RFAPI_MONITOR_EXTERIOR(par)->source =
skiplist_new(
0, NULL,
(void (*)(void *))prefix_free);
0, NULL, prefix_free_lists);
agg_lock_node(par); /* sl */
}
skiplist_insert(RFAPI_MONITOR_EXTERIOR(par)->source,
Expand Down
3 changes: 1 addition & 2 deletions eigrpd/eigrp_network.c
Original file line number Diff line number Diff line change
Expand Up @@ -327,8 +327,7 @@ int eigrp_network_unset(struct eigrp *eigrp, struct prefix *p)
if (!IPV4_ADDR_SAME(&pref->u.prefix4, &p->u.prefix4))
return 0;

prefix_ipv4_free(rn->info);
rn->info = NULL;
prefix_ipv4_free((struct prefix_ipv4 **)&rn->info);
route_unlock_node(rn); /* initial reference */

/* Find interfaces that not configured already. */
Expand Down
2 changes: 1 addition & 1 deletion eigrpd/eigrp_topology.c
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,7 @@ void eigrp_prefix_entry_delete(struct eigrp *eigrp, struct route_table *table,
list_delete(&pe->entries);
list_delete(&pe->rij);
eigrp_zebra_route_delete(eigrp, pe->destination);
prefix_free(pe->destination);
prefix_free(&pe->destination);

rn->info = NULL;
route_unlock_node(rn); // Lookup above
Expand Down
2 changes: 1 addition & 1 deletion eigrpd/eigrp_zebra.c
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,7 @@ static int eigrp_interface_address_delete(ZAPI_CALLBACK_ARGS)
if (prefix_cmp(&ei->address, c->address) == 0)
eigrp_if_free(ei, INTERFACE_DOWN_BY_ZEBRA);

connected_free(c);
connected_free(&c);

return 0;
}
Expand Down
10 changes: 5 additions & 5 deletions isisd/isis_circuit.c
Original file line number Diff line number Diff line change
Expand Up @@ -338,7 +338,7 @@ void isis_circuit_del_addr(struct isis_circuit *circuit,

if (ip) {
listnode_delete(circuit->ip_addrs, ip);
prefix_ipv4_free(ip);
prefix_ipv4_free(&ip);
if (circuit->area)
lsp_regenerate_schedule(circuit->area,
circuit->is_type, 0);
Expand All @@ -358,7 +358,7 @@ void isis_circuit_del_addr(struct isis_circuit *circuit,
zlog_warn("End of addresses");
}

prefix_ipv4_free(ipv4);
prefix_ipv4_free(&ipv4);
}
if (connected->address->family == AF_INET6) {
ipv6 = prefix_ipv6_new();
Expand All @@ -374,7 +374,7 @@ void isis_circuit_del_addr(struct isis_circuit *circuit,
}
if (ip6) {
listnode_delete(circuit->ipv6_link, ip6);
prefix_ipv6_free(ip6);
prefix_ipv6_free(&ip6);
found = 1;
}
} else {
Expand All @@ -386,7 +386,7 @@ void isis_circuit_del_addr(struct isis_circuit *circuit,
}
if (ip6) {
listnode_delete(circuit->ipv6_non_link, ip6);
prefix_ipv6_free(ip6);
prefix_ipv6_free(&ip6);
found = 1;
}
}
Expand Down Expand Up @@ -417,7 +417,7 @@ void isis_circuit_del_addr(struct isis_circuit *circuit,
lsp_regenerate_schedule(circuit->area, circuit->is_type,
0);

prefix_ipv6_free(ipv6);
prefix_ipv6_free(&ipv6);
}
return;
}
Expand Down
2 changes: 1 addition & 1 deletion isisd/isis_zebra.c
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ static int isis_zebra_if_address_del(ZAPI_CALLBACK_ARGS)

if (if_is_operative(ifp))
isis_circuit_del_addr(circuit_scan_by_ifp(ifp), c);
connected_free(c);
connected_free(&c);

return 0;
}
Expand Down
2 changes: 1 addition & 1 deletion ldpd/ldp_zebra.c
Original file line number Diff line number Diff line change
Expand Up @@ -368,7 +368,7 @@ ldp_interface_address_delete(ZAPI_CALLBACK_ARGS)

ifp = ifc->ifp;
ifc2kaddr(ifp, ifc, &ka);
connected_free(ifc);
connected_free(&ifc);

/* Filter invalid addresses. */
if (bad_addr(ka.af, &ka.addr))
Expand Down
58 changes: 35 additions & 23 deletions lib/if.c
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,13 @@ static int if_cmp_index_func(const struct interface *ifp1,
return ifp1->ifindex - ifp2->ifindex;
}

static void ifp_connected_free(void *arg)
{
struct connected *c = arg;

connected_free(&c);
}

/* Create new interface structure. */
static struct interface *if_new(vrf_id_t vrf_id)
{
Expand All @@ -153,7 +160,7 @@ static struct interface *if_new(vrf_id_t vrf_id)
ifp->vrf_id = vrf_id;

ifp->connected = list_new();
ifp->connected->del = (void (*)(void *))connected_free;
ifp->connected->del = ifp_connected_free;

ifp->nbr_connected = list_new();
ifp->nbr_connected->del = (void (*)(void *))nbr_connected_free;
Expand All @@ -178,7 +185,7 @@ void if_destroy_via_zapi(struct interface *ifp)

if_set_index(ifp, IFINDEX_INTERNAL);
if (!ifp->configured)
if_delete(ifp);
if_delete(&ifp);
}

void if_up_via_zapi(struct interface *ifp)
Expand Down Expand Up @@ -276,27 +283,29 @@ void if_delete_retain(struct interface *ifp)
}

/* Delete and free interface structure. */
void if_delete(struct interface *ifp)
void if_delete(struct interface **ifp)
{
struct interface *ptr = *ifp;
struct vrf *vrf;

vrf = vrf_lookup_by_id(ifp->vrf_id);
vrf = vrf_lookup_by_id(ptr->vrf_id);
assert(vrf);

IFNAME_RB_REMOVE(vrf, ifp);
if (ifp->ifindex != IFINDEX_INTERNAL)
IFINDEX_RB_REMOVE(vrf, ifp);
IFNAME_RB_REMOVE(vrf, ptr);
if (ptr->ifindex != IFINDEX_INTERNAL)
IFINDEX_RB_REMOVE(vrf, ptr);

if_delete_retain(ifp);
if_delete_retain(ptr);

list_delete(&ifp->connected);
list_delete(&ifp->nbr_connected);
list_delete(&ptr->connected);
list_delete(&ptr->nbr_connected);

if_link_params_free(ifp);
if_link_params_free(ptr);

XFREE(MTYPE_TMP, ifp->desc);
XFREE(MTYPE_TMP, ptr->desc);

XFREE(MTYPE_IF, ifp);
XFREE(MTYPE_IF, ptr);
*ifp = NULL;
}

/* Used only internally to check within VRF only */
Expand Down Expand Up @@ -866,24 +875,27 @@ struct nbr_connected *nbr_connected_new(void)
}

/* Free connected structure. */
void connected_free(struct connected *connected)
void connected_free(struct connected **connected)
{
if (connected->address)
prefix_free(connected->address);
struct connected *ptr = *connected;

if (ptr->address)
prefix_free(&ptr->address);

if (connected->destination)
prefix_free(connected->destination);
if (ptr->destination)
prefix_free(&ptr->destination);

XFREE(MTYPE_CONNECTED_LABEL, connected->label);
XFREE(MTYPE_CONNECTED_LABEL, ptr->label);

XFREE(MTYPE_CONNECTED, connected);
XFREE(MTYPE_CONNECTED, ptr);
*connected = NULL;
}

/* Free nbr connected structure. */
void nbr_connected_free(struct nbr_connected *connected)
{
if (connected->address)
prefix_free(connected->address);
prefix_free(&connected->address);

XFREE(MTYPE_NBR_CONNECTED, connected);
}
Expand Down Expand Up @@ -1159,7 +1171,7 @@ void if_terminate(struct vrf *vrf)
ifp->node->info = NULL;
route_unlock_node(ifp->node);
}
if_delete(ifp);
if_delete(&ifp);
}
}

Expand Down Expand Up @@ -1541,7 +1553,7 @@ static int lib_interface_destroy(enum nb_event event,
ifp = nb_running_unset_entry(dnode);

ifp->configured = false;
if_delete(ifp);
if_delete(&ifp);
break;
}

Expand Down
4 changes: 2 additions & 2 deletions lib/if.h
Original file line number Diff line number Diff line change
Expand Up @@ -513,7 +513,7 @@ extern void if_delete_retain(struct interface *);

/* Delete and free the interface structure: calls if_delete_retain and then
deletes it from the interface list and frees the structure. */
extern void if_delete(struct interface *);
extern void if_delete(struct interface **ifp);

extern int if_is_up(const struct interface *ifp);
extern int if_is_running(const struct interface *ifp);
Expand Down Expand Up @@ -543,7 +543,7 @@ extern ifindex_t ifname2ifindex(const char *ifname, vrf_id_t vrf_id);

/* Connected address functions. */
extern struct connected *connected_new(void);
extern void connected_free(struct connected *);
extern void connected_free(struct connected **connected);
extern void connected_add(struct interface *, struct connected *);
extern struct connected *
connected_add_by_prefix(struct interface *, struct prefix *, struct prefix *);
Expand Down
Loading

0 comments on commit 3160b7f

Please sign in to comment.