Merge pull request #14781 from donaldsharp/frr_memory_leaks_cleanup

Frr memory leaks cleanup
This commit is contained in:
Donatas Abraitis 2023-11-13 21:17:16 +02:00 committed by GitHub
commit 04a587f480
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
64 changed files with 109 additions and 57 deletions

View File

@ -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);

View File

@ -103,6 +103,7 @@ static void __attribute__((noreturn)) ospf6_exit(int status)
zclient_free(zclient);
}
ospf6_master_delete();
frr_fini();
exit(status);
}

View File

@ -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);
@ -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);
}
@ -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);

View File

@ -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);

View File

@ -89,6 +89,7 @@ static void sigint(void)
zlog_notice("Terminating on signal");
bfd_protocol_integration_set_shutdown(true);
ospf_terminate();
exit(0);
}

View File

@ -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);
}
@ -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

View File

@ -71,6 +71,8 @@ static void sigint(void)
pbr_vrf_terminate();
pbr_zebra_destroy();
frr_fini();
exit(0);

View File

@ -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;

View File

@ -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);

View File

@ -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)

View File

@ -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);

View File

@ -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);
}

View File

@ -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;
@ -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);
@ -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");

View File

@ -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);
}

View File

@ -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);

View File

@ -1,5 +1,4 @@
log stdout notifications
log monitor notifications
!log commands
!
!debug bgp zebra

View File

@ -4,7 +4,6 @@ hostname r1
password zebra
!
log stdout notifications
log monitor notifications
log commands
!
router bgp 65001

View File

@ -4,7 +4,6 @@ hostname r2
password zebra
!
log stdout notifications
log monitor notifications
log commands
!
router bgp 65002

View File

@ -4,7 +4,6 @@ hostname r2
password zebra
!
log stdout notifications
log monitor notifications
log commands
!
router bgp 65001

View File

@ -4,7 +4,6 @@ hostname pe1
password zebra
!
log stdout notifications
log monitor notifications
log commands
!
router bgp 65001

View File

@ -4,7 +4,6 @@ hostname r1
password zebra
!
log stdout notifications
log monitor notifications
log commands
!
!debug bgp neighbor-events

View File

@ -4,7 +4,6 @@ hostname r1
password zebra
!
log stdout notifications
log monitor notifications
log commands
!
!debug zebra packet

View File

@ -4,7 +4,6 @@ hostname r2
password zebra
!
log stdout notifications
log monitor notifications
log commands
!
!debug bgp neighbor-events

View File

@ -4,7 +4,6 @@ hostname r2
password zebra
!
log stdout notifications
log monitor notifications
log commands
!
!debug zebra packet

View File

@ -6,7 +6,6 @@ hostname r1
password zebra
!
log stdout notifications
log monitor notifications
log commands
!
!debug bgp neighbor-events

View File

@ -4,7 +4,6 @@ hostname r1
password zebra
!
log stdout notifications
log monitor notifications
log commands
!
! debug zebra packet

View File

@ -6,7 +6,6 @@ hostname r2
password zebra
!
log stdout notifications
log monitor notifications
log commands
!
!debug bgp neighbor-events

View File

@ -4,7 +4,6 @@ hostname r2
password zebra
!
log stdout notifications
log monitor notifications
log commands
!
! debug zebra packet

View File

@ -6,7 +6,6 @@ hostname r1
password zebra
!
log stdout notifications
log monitor notifications
log commands
!
!debug bgp neighbor-events

View File

@ -4,7 +4,6 @@ hostname r1
password zebra
!
log stdout notifications
log monitor notifications
log commands
!
!debug zebra packet

View File

@ -6,7 +6,6 @@ hostname r2
password zebra
!
log stdout notifications
log monitor notifications
log commands
!
!debug bgp neighbor-events

View File

@ -4,7 +4,6 @@ hostname r2
password zebra
!
log stdout notifications
log monitor notifications
log commands
!
!debug zebra packet

View File

@ -6,7 +6,6 @@ hostname r1
password zebra
!
log stdout notifications
log monitor notifications
log commands
!
!debug bgp neighbor-events

View File

@ -4,7 +4,6 @@ hostname r1
password zebra
!
log stdout notifications
log monitor notifications
log commands
!
!debug zebra packet

View File

@ -6,7 +6,6 @@ hostname r2
password zebra
!
log stdout notifications
log monitor notifications
log commands
!
!debug bgp neighbor-events

View File

@ -4,7 +4,6 @@ hostname r2
password zebra
!
log stdout notifications
log monitor notifications
log commands
!
!debug zebra packet

View File

@ -4,7 +4,6 @@ hostname ce1
password zebra
!
log stdout notifications
log monitor notifications
log commands
!
router bgp 65002

View File

@ -4,7 +4,6 @@ hostname pe1
password zebra
!
log stdout notifications
log monitor notifications
log commands
!
router bgp 65001

View File

@ -3,7 +3,6 @@ log file zebra.log
hostname rt1
!
log stdout notifications
log monitor notifications
log commands
!
!debug zebra packet

View File

@ -3,7 +3,6 @@ log file zebra.log
hostname rt2
!
log stdout notifications
log monitor notifications
log commands
!
!debug zebra packet

View File

@ -3,7 +3,6 @@ log file zebra.log
hostname rt3
!
log stdout notifications
log monitor notifications
log commands
!
!debug zebra packet

View File

@ -3,7 +3,6 @@ log file zebra.log
hostname rt0
!
!log stdout notifications
!log monitor notifications
!log commands
!
debug zebra packet

View File

@ -3,7 +3,6 @@ log file zebra.log
hostname rt1
!
log stdout notifications
log monitor notifications
log commands
!
!debug zebra packet

View File

@ -3,7 +3,6 @@ log file zebra.log
hostname rt2
!
log stdout notifications
log monitor notifications
log commands
!
!debug zebra packet

View File

@ -3,7 +3,6 @@ log file zebra.log
hostname rt3
!
log stdout notifications
log monitor notifications
log commands
!
!debug zebra packet

View File

@ -3,7 +3,6 @@ log file zebra.log
hostname rt4
!
log stdout notifications
log monitor notifications
log commands
!
!debug zebra packet

View File

@ -3,7 +3,6 @@ log file zebra.log
hostname rt5
!
log stdout notifications
log monitor notifications
log commands
!
!debug zebra packet

View File

@ -3,7 +3,6 @@ log file zebra.log
hostname rt6
!
log stdout notifications
log monitor notifications
log commands
!
!debug zebra packet

View File

@ -3,7 +3,6 @@ log file zebra.log
hostname rt7
!
log stdout notifications
log monitor notifications
log commands
!
!debug zebra packet

View File

@ -3,7 +3,6 @@ log file zebra.log
hostname rt8
!
log stdout notifications
log monitor notifications
log commands
!
!debug zebra packet

View File

@ -3,7 +3,6 @@ log file zebra.log
hostname rt9
!
log stdout notifications
log monitor notifications
log commands
!
!debug zebra packet

View File

@ -1,7 +1,6 @@
hostname r1
!
log stdout notifications
log monitor notifications
log commands
log file sharpd.log debugging
!

View File

@ -4,7 +4,6 @@ hostname r1
! debug zebra rib detailed
!
log stdout notifications
log monitor notifications
log commands
log file zebra.log debugging
!

View File

@ -1,7 +1,6 @@
hostname r1
!
log stdout notifications
log monitor notifications
log commands
log file sharpd.log debugging
!

View File

@ -4,7 +4,6 @@ hostname r1
! debug zebra rib detailed
!
log stdout notifications
log monitor notifications
log commands
log file zebra.log debugging
!

View File

@ -1,7 +1,6 @@
hostname r1
!
log stdout notifications
log monitor notifications
log commands
log file sharpd.log debugging
!

View File

@ -4,7 +4,6 @@ hostname r1
! debug zebra rib detailed
!
log stdout notifications
log monitor notifications
log commands
log file zebra.log debugging
!

View File

@ -1,7 +1,6 @@
hostname r1
!
log stdout notifications
log monitor notifications
log commands
log file staticd.log debugging
!

View File

@ -4,7 +4,6 @@ hostname r1
! debug zebra rib detailed
!
log stdout notifications
log monitor notifications
log commands
log file zebra.log debugging
!

View File

@ -1,7 +1,6 @@
log file zebra.log
!
log stdout notifications
log monitor notifications
log commands
!
! debug zebra packet

View File

@ -1,7 +1,6 @@
log file zebra.log
!
log stdout notifications
log monitor notifications
log commands
!
! debug zebra packet

View File

@ -1924,8 +1924,11 @@ void kernel_terminate(struct zebra_ns *zns, bool complete)
/* During zebra shutdown, we need to leave the dataplane socket
* around until all work is done.
*/
if (complete)
if (complete) {
kernel_nlsock_fini(&zns->netlink_dplane_out);
XFREE(MTYPE_NL_BUF, nl_batch_tx_buf);
}
}
/*

View File

@ -627,6 +627,8 @@ void zebra_mlag_init(void)
void zebra_mlag_terminate(void)
{
stream_fifo_free(zrouter.mlag_info.mlag_fifo);
zrouter.mlag_info.mlag_fifo = NULL;
}

View File

@ -265,6 +265,12 @@ static int zebra_vrf_delete(struct vrf *vrf)
otable_fini(&zvrf->other_tables);
XFREE(MTYPE_ZEBRA_VRF, zvrf);
if (vrf->ns_ctxt) {
ns_delete(vrf->ns_ctxt);
vrf->ns_ctxt = NULL;
}
vrf->info = NULL;
return 0;