Skip to content

Commit

Permalink
*: Convert connected_free to a double pointer
Browse files Browse the repository at this point in the history
Set the connected pointer to set the pointer to NULL.

Signed-off-by: Donald Sharp <sharpd@cumulusnetworks.com>
  • Loading branch information
donaldsharp committed Nov 2, 2019
1 parent 63265b5 commit 721c085
Show file tree
Hide file tree
Showing 17 changed files with 39 additions and 29 deletions.
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 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
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
26 changes: 18 additions & 8 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 Down Expand Up @@ -866,17 +873,20 @@ 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. */
Expand Down
2 changes: 1 addition & 1 deletion lib/if.h
Original file line number Diff line number Diff line change
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
2 changes: 1 addition & 1 deletion nhrpd/nhrp_interface.c
Original file line number Diff line number Diff line change
Expand Up @@ -364,7 +364,7 @@ int nhrp_interface_address_delete(ZAPI_CALLBACK_ARGS)

nhrp_interface_update_address(
ifc->ifp, family2afi(PREFIX_FAMILY(ifc->address)), 0);
connected_free(ifc);
connected_free(&ifc);

return 0;
}
Expand Down
2 changes: 1 addition & 1 deletion ospf6d/ospf6_zebra.c
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ static int ospf6_zebra_if_address_update_delete(ZAPI_CALLBACK_ARGS)
ospf6_interface_state_update(c->ifp);
}

connected_free(c);
connected_free(&c);

return 0;
}
Expand Down
4 changes: 2 additions & 2 deletions ospfd/ospf_zebra.c
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ static int ospf_interface_address_delete(ZAPI_CALLBACK_ARGS)

rn = route_node_lookup(IF_OIFS(ifp), &p);
if (!rn) {
connected_free(c);
connected_free(&c);
return 0;
}

Expand All @@ -163,7 +163,7 @@ static int ospf_interface_address_delete(ZAPI_CALLBACK_ARGS)

ospf_if_interface(c->ifp);

connected_free(c);
connected_free(&c);

return 0;
}
Expand Down
2 changes: 1 addition & 1 deletion pbrd/pbr_zebra.c
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ static int interface_address_delete(ZAPI_CALLBACK_ARGS)
"%s: %s deleted %s", __PRETTY_FUNCTION__, c->ifp->name,
prefix2str(c->address, buf, sizeof(buf)));

connected_free(c);
connected_free(&c);
return 0;
}

Expand Down
2 changes: 1 addition & 1 deletion pimd/pim_zebra.c
Original file line number Diff line number Diff line change
Expand Up @@ -233,7 +233,7 @@ static int pim_zebra_if_address_del(ZAPI_CALLBACK_ARGS)
pim_i_am_rp_re_evaluate(pim);
}

connected_free(c);
connected_free(&c);
return 0;
}

Expand Down
2 changes: 1 addition & 1 deletion ripd/rip_interface.c
Original file line number Diff line number Diff line change
Expand Up @@ -648,7 +648,7 @@ int rip_interface_address_delete(ZAPI_CALLBACK_ARGS)
rip_apply_address_del(ifc);
}

connected_free(ifc);
connected_free(&ifc);
}

return 0;
Expand Down
2 changes: 1 addition & 1 deletion ripngd/ripng_interface.c
Original file line number Diff line number Diff line change
Expand Up @@ -430,7 +430,7 @@ int ripng_interface_address_delete(ZAPI_CALLBACK_ARGS)
/* Check wether this prefix needs to be removed. */
ripng_apply_address_del(ifc);
}
connected_free(ifc);
connected_free(&ifc);
}

return 0;
Expand Down
2 changes: 1 addition & 1 deletion sharpd/sharp_zebra.c
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ static int interface_address_delete(ZAPI_CALLBACK_ARGS)
if (!c)
return 0;

connected_free(c);
connected_free(&c);
return 0;
}

Expand Down
2 changes: 1 addition & 1 deletion staticd/static_zebra.c
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ static int interface_address_delete(ZAPI_CALLBACK_ARGS)
if (!c)
return 0;

connected_free(c);
connected_free(&c);
return 0;
}

Expand Down
4 changes: 2 additions & 2 deletions zebra/connected.c
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ static void connected_withdraw(struct connected *ifc)

if (!CHECK_FLAG(ifc->conf, ZEBRA_IFC_CONFIGURED)) {
listnode_delete(ifc->ifp->connected, ifc);
connected_free(ifc);
connected_free(&ifc);
}
}

Expand Down Expand Up @@ -177,7 +177,7 @@ static void connected_update(struct interface *ifp, struct connected *ifc)
*/
if (connected_same(current, ifc)) {
/* nothing to do */
connected_free(ifc);
connected_free(&ifc);
return;
}

Expand Down
8 changes: 4 additions & 4 deletions zebra/interface.c
Original file line number Diff line number Diff line change
Expand Up @@ -738,7 +738,7 @@ static void if_delete_connected(struct interface *ifp)
ZEBRA_IFC_CONFIGURED)) {
listnode_delete(ifp->connected,
ifc);
connected_free(ifc);
connected_free(&ifc);
} else
last = node;
}
Expand All @@ -759,7 +759,7 @@ static void if_delete_connected(struct interface *ifp)
last = node;
else {
listnode_delete(ifp->connected, ifc);
connected_free(ifc);
connected_free(&ifc);
}
} else {
last = node;
Expand Down Expand Up @@ -2878,7 +2878,7 @@ static int ip_address_uninstall(struct vty *vty, struct interface *ifp,
if (!CHECK_FLAG(ifc->conf, ZEBRA_IFC_QUEUED)
|| !CHECK_FLAG(ifp->status, ZEBRA_INTERFACE_ACTIVE)) {
listnode_delete(ifp->connected, ifc);
connected_free(ifc);
connected_free(&ifc);
return CMD_WARNING_CONFIG_FAILED;
}

Expand Down Expand Up @@ -3103,7 +3103,7 @@ static int ipv6_address_uninstall(struct vty *vty, struct interface *ifp,
if (!CHECK_FLAG(ifc->conf, ZEBRA_IFC_QUEUED)
|| !CHECK_FLAG(ifp->status, ZEBRA_INTERFACE_ACTIVE)) {
listnode_delete(ifp->connected, ifc);
connected_free(ifc);
connected_free(&ifc);
return CMD_WARNING_CONFIG_FAILED;
}

Expand Down

0 comments on commit 721c085

Please sign in to comment.