Skip to content

Commit

Permalink
Merge pull request #14781 from donaldsharp/frr_memory_leaks_cleanup
Browse files Browse the repository at this point in the history
Frr memory leaks cleanup
  • Loading branch information
ton31337 authored Nov 13, 2023
2 parents c62c018 + 3edeaa9 commit 04a587f
Show file tree
Hide file tree
Showing 64 changed files with 109 additions and 57 deletions.
2 changes: 2 additions & 0 deletions babeld/babel_main.c
Original file line number Diff line number Diff line change
Expand Up @@ -308,6 +308,8 @@ babel_exit_properly(void)
babel_save_state_file();
debugf(BABEL_DEBUG_COMMON, "Remove pid file.");
debugf(BABEL_DEBUG_COMMON, "Done.");

vrf_terminate();
frr_fini();

exit(0);
Expand Down
1 change: 1 addition & 0 deletions ospf6d/ospf6_main.c
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,7 @@ static void __attribute__((noreturn)) ospf6_exit(int status)
zclient_free(zclient);
}

ospf6_master_delete();
frr_fini();
exit(status);
}
Expand Down
13 changes: 13 additions & 0 deletions ospf6d/ospf6_top.c
Original file line number Diff line number Diff line change
Expand Up @@ -486,6 +486,7 @@ void ospf6_delete(struct ospf6 *o)
struct ospf6_area *oa;
struct vrf *vrf;
struct ospf6_external_aggr_rt *aggr;
uint32_t i;

QOBJ_UNREG(o);

Expand Down Expand Up @@ -532,6 +533,13 @@ void ospf6_delete(struct ospf6 *o)
}
route_table_finish(o->rt_aggr_tbl);

for (i = 0; i <= ZEBRA_ROUTE_MAX; i++) {
if (!o->redist[i])
continue;

list_delete(&o->redist[i]);
}

XFREE(MTYPE_OSPF6_TOP, o->name);
XFREE(MTYPE_OSPF6_TOP, o);
}
Expand Down Expand Up @@ -576,6 +584,11 @@ void ospf6_master_init(struct event_loop *master)
om6->master = master;
}

void ospf6_master_delete(void)
{
list_delete(&om6->ospf6);
}

static void ospf6_maxage_remover(struct event *thread)
{
struct ospf6 *o = (struct ospf6 *)EVENT_ARG(thread);
Expand Down
2 changes: 2 additions & 0 deletions ospf6d/ospf6_top.h
Original file line number Diff line number Diff line change
Expand Up @@ -236,6 +236,8 @@ extern struct ospf6_master *om6;

/* prototypes */
extern void ospf6_master_init(struct event_loop *master);
extern void ospf6_master_delete(void);

extern void install_element_ospf6_clear_process(void);
extern void ospf6_top_init(void);
extern void ospf6_delete(struct ospf6 *o);
Expand Down
1 change: 1 addition & 0 deletions ospfd/ospf_main.c
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@ static void sigint(void)
zlog_notice("Terminating on signal");
bfd_protocol_integration_set_shutdown(true);
ospf_terminate();

exit(0);
}

Expand Down
2 changes: 2 additions & 0 deletions ospfd/ospfd.c
Original file line number Diff line number Diff line change
Expand Up @@ -595,6 +595,7 @@ static void ospf_deferred_shutdown_finish(struct ospf *ospf)
/* ospfd being shut-down? If so, was this the last ospf instance? */
if (CHECK_FLAG(om->options, OSPF_MASTER_SHUTDOWN)
&& (listcount(om->ospf) == 0)) {
route_map_finish();
frr_fini();
exit(0);
}
Expand Down Expand Up @@ -678,6 +679,7 @@ void ospf_terminate(void)
/* Cleanup vrf info */
ospf_vrf_terminate();

route_map_finish();
/* Deliberately go back up, hopefully to thread scheduler, as
* One or more ospf_finish()'s may have deferred shutdown to a timer
* thread
Expand Down
2 changes: 2 additions & 0 deletions pbrd/pbr_main.c
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,8 @@ static void sigint(void)

pbr_vrf_terminate();

pbr_zebra_destroy();

frr_fini();

exit(0);
Expand Down
10 changes: 10 additions & 0 deletions pbrd/pbr_zebra.c
Original file line number Diff line number Diff line change
Expand Up @@ -419,6 +419,16 @@ void pbr_zebra_init(void)
zclient->zebra_connected = zebra_connected;
}

void pbr_zebra_destroy(void)
{
if (zclient == NULL)
return;

zclient_stop(zclient);
zclient_free(zclient);
zclient = NULL;
}

void pbr_send_rnh(struct nexthop *nhop, bool reg)
{
uint32_t command;
Expand Down
1 change: 1 addition & 0 deletions pbrd/pbr_zebra.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ struct pbr_interface {
extern struct event_loop *master;

extern void pbr_zebra_init(void);
extern void pbr_zebra_destroy(void);

extern void route_add(struct pbr_nexthop_group_cache *pnhgc,
struct nexthop_group nhg, afi_t install_afi);
Expand Down
3 changes: 3 additions & 0 deletions pimd/pim_vxlan.c
Original file line number Diff line number Diff line change
Expand Up @@ -1210,6 +1210,9 @@ void pim_vxlan_exit(struct pim_instance *pim)
{
hash_clean_and_free(&pim->vxlan.sg_hash,
(void (*)(void *))pim_vxlan_sg_del_item);

if (vxlan_info.work_list)
list_delete(&vxlan_info.work_list);
}

void pim_vxlan_terminate(void)
Expand Down
12 changes: 12 additions & 0 deletions ripd/rip_main.c
Original file line number Diff line number Diff line change
Expand Up @@ -67,12 +67,24 @@ static void sighup(void)
/* SIGINT handler. */
static void sigint(void)
{
struct vrf *vrf;

zlog_notice("Terminating on signal");

bfd_protocol_integration_set_shutdown(true);

RB_FOREACH (vrf, vrf_name_head, &vrfs_by_name) {
if (!vrf->info)
continue;

rip_clean(vrf->info);
}

rip_vrf_terminate();
if_rmap_terminate();
rip_zclient_stop();

route_map_finish();
frr_fini();

exit(0);
Expand Down
12 changes: 12 additions & 0 deletions ripngd/ripng_main.c
Original file line number Diff line number Diff line change
Expand Up @@ -66,11 +66,23 @@ static void sighup(void)
/* SIGINT handler. */
static void sigint(void)
{
struct vrf *vrf;

zlog_notice("Terminating on signal");

RB_FOREACH (vrf, vrf_name_head, &vrfs_by_name) {
if (!vrf->info)
continue;

ripng_clean(vrf->info);
}

ripng_vrf_terminate();
if_rmap_terminate();
ripng_zebra_stop();

route_map_finish();

frr_fini();
exit(0);
}
Expand Down
31 changes: 21 additions & 10 deletions sharpd/sharp_main.c
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,22 @@ struct zebra_privs_t sharp_privs = {

struct option longopts[] = {{0}};

struct sharp_global sg;

static void sharp_global_init(void)
{
memset(&sg, 0, sizeof(sg));
sg.nhs = list_new();
sg.ted = NULL;
sg.srv6_locators = list_new();
}

static void sharp_global_destroy(void)
{
list_delete(&sg.nhs);
list_delete(&sg.srv6_locators);
}

/* Master of threads. */
struct event_loop *master;

Expand All @@ -68,6 +84,11 @@ static void sigint(void)
{
zlog_notice("Terminating on signal");

vrf_terminate();
sharp_zebra_terminate();

sharp_global_destroy();

frr_fini();

exit(0);
Expand Down Expand Up @@ -118,16 +139,6 @@ FRR_DAEMON_INFO(sharpd, SHARP, .vty_port = SHARP_VTY_PORT,
.n_yang_modules = array_size(sharpd_yang_modules),
);

struct sharp_global sg;

static void sharp_global_init(void)
{
memset(&sg, 0, sizeof(sg));
sg.nhs = list_new();
sg.ted = NULL;
sg.srv6_locators = list_new();
}

static void sharp_start_configuration(void)
{
zlog_debug("Configuration has started to be read");
Expand Down
14 changes: 14 additions & 0 deletions sharpd/sharp_zebra.c
Original file line number Diff line number Diff line change
Expand Up @@ -1089,3 +1089,17 @@ void sharp_zebra_init(void)
zclient->zebra_connected = zebra_connected;
zclient->zebra_buffer_write_ready = sharp_zclient_buffer_ready;
}

void sharp_zebra_terminate(void)
{
struct sharp_zclient *node = sharp_clients_head;

while (node) {
sharp_zclient_delete(node->client->session_id);

node = sharp_clients_head;
}

zclient_stop(zclient);
zclient_free(zclient);
}
1 change: 1 addition & 0 deletions sharpd/sharp_zebra.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
#define __SHARP_ZEBRA_H__

extern void sharp_zebra_init(void);
extern void sharp_zebra_terminate(void);

/* Add and delete extra zapi client sessions, for testing */
int sharp_zclient_create(uint32_t session_id);
Expand Down
1 change: 0 additions & 1 deletion tests/topotests/bgp_prefix_sid2/r1/bgpd.conf
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
log stdout notifications
log monitor notifications
!log commands
!
!debug bgp zebra
Expand Down
1 change: 0 additions & 1 deletion tests/topotests/bgp_srv6l3vpn_over_ipv6/r1/bgpd.conf
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ hostname r1
password zebra
!
log stdout notifications
log monitor notifications
log commands
!
router bgp 65001
Expand Down
1 change: 0 additions & 1 deletion tests/topotests/bgp_srv6l3vpn_over_ipv6/r2/bgpd.conf
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ hostname r2
password zebra
!
log stdout notifications
log monitor notifications
log commands
!
router bgp 65002
Expand Down
1 change: 0 additions & 1 deletion tests/topotests/bgp_srv6l3vpn_over_ipv6/r3/bgpd.conf
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ hostname r2
password zebra
!
log stdout notifications
log monitor notifications
log commands
!
router bgp 65001
Expand Down
1 change: 0 additions & 1 deletion tests/topotests/bgp_srv6l3vpn_route_leak/pe1/bgpd.conf
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ hostname pe1
password zebra
!
log stdout notifications
log monitor notifications
log commands
!
router bgp 65001
Expand Down
1 change: 0 additions & 1 deletion tests/topotests/bgp_srv6l3vpn_sid/r1/bgpd.conf
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ hostname r1
password zebra
!
log stdout notifications
log monitor notifications
log commands
!
!debug bgp neighbor-events
Expand Down
1 change: 0 additions & 1 deletion tests/topotests/bgp_srv6l3vpn_sid/r1/zebra.conf
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ hostname r1
password zebra
!
log stdout notifications
log monitor notifications
log commands
!
!debug zebra packet
Expand Down
1 change: 0 additions & 1 deletion tests/topotests/bgp_srv6l3vpn_sid/r2/bgpd.conf
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ hostname r2
password zebra
!
log stdout notifications
log monitor notifications
log commands
!
!debug bgp neighbor-events
Expand Down
1 change: 0 additions & 1 deletion tests/topotests/bgp_srv6l3vpn_sid/r2/zebra.conf
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ hostname r2
password zebra
!
log stdout notifications
log monitor notifications
log commands
!
!debug zebra packet
Expand Down
1 change: 0 additions & 1 deletion tests/topotests/bgp_srv6l3vpn_to_bgp_vrf/r1/bgpd.conf
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ hostname r1
password zebra
!
log stdout notifications
log monitor notifications
log commands
!
!debug bgp neighbor-events
Expand Down
1 change: 0 additions & 1 deletion tests/topotests/bgp_srv6l3vpn_to_bgp_vrf/r1/zebra.conf
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ hostname r1
password zebra
!
log stdout notifications
log monitor notifications
log commands
!
! debug zebra packet
Expand Down
1 change: 0 additions & 1 deletion tests/topotests/bgp_srv6l3vpn_to_bgp_vrf/r2/bgpd.conf
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ hostname r2
password zebra
!
log stdout notifications
log monitor notifications
log commands
!
!debug bgp neighbor-events
Expand Down
1 change: 0 additions & 1 deletion tests/topotests/bgp_srv6l3vpn_to_bgp_vrf/r2/zebra.conf
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ hostname r2
password zebra
!
log stdout notifications
log monitor notifications
log commands
!
! debug zebra packet
Expand Down
1 change: 0 additions & 1 deletion tests/topotests/bgp_srv6l3vpn_to_bgp_vrf2/r1/bgpd.conf
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ hostname r1
password zebra
!
log stdout notifications
log monitor notifications
log commands
!
!debug bgp neighbor-events
Expand Down
1 change: 0 additions & 1 deletion tests/topotests/bgp_srv6l3vpn_to_bgp_vrf2/r1/zebra.conf
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ hostname r1
password zebra
!
log stdout notifications
log monitor notifications
log commands
!
!debug zebra packet
Expand Down
1 change: 0 additions & 1 deletion tests/topotests/bgp_srv6l3vpn_to_bgp_vrf2/r2/bgpd.conf
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ hostname r2
password zebra
!
log stdout notifications
log monitor notifications
log commands
!
!debug bgp neighbor-events
Expand Down
1 change: 0 additions & 1 deletion tests/topotests/bgp_srv6l3vpn_to_bgp_vrf2/r2/zebra.conf
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ hostname r2
password zebra
!
log stdout notifications
log monitor notifications
log commands
!
!debug zebra packet
Expand Down
1 change: 0 additions & 1 deletion tests/topotests/bgp_srv6l3vpn_to_bgp_vrf3/r1/bgpd.conf
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ hostname r1
password zebra
!
log stdout notifications
log monitor notifications
log commands
!
!debug bgp neighbor-events
Expand Down
Loading

0 comments on commit 04a587f

Please sign in to comment.