From 2a4dbd8d37aa8e367d9ba1a0e86fdb6de9e5280c Mon Sep 17 00:00:00 2001 From: Richard Fuchs Date: Thu, 11 Jun 2020 11:56:27 -0400 Subject: [PATCH] TT#28300 add cleanup of global interface structs Change-Id: I326d72c88505c532b19e98165666f10d4692fafc --- daemon/main.c | 1 + daemon/media_socket.c | 51 ++++++++++++++++++++++++++++++++++++++++++ include/media_socket.h | 1 + 3 files changed, 53 insertions(+) diff --git a/daemon/main.c b/daemon/main.c index 9c61980c6..ade1a5d83 100644 --- a/daemon/main.c +++ b/daemon/main.c @@ -944,6 +944,7 @@ int main(int argc, char **argv) { unfill_initial_rtpe_cfg(&initial_rtpe_config); options_free(); + interfaces_free(); return 0; } diff --git a/daemon/media_socket.c b/daemon/media_socket.c index 90c2c0a36..91ae98863 100644 --- a/daemon/media_socket.c +++ b/daemon/media_socket.c @@ -2099,3 +2099,54 @@ void play_buffered(struct jb_packet *cp) { stream_packet(&phc); jb_packet_free(&cp); } + +void interfaces_free(void) { + struct local_intf *ifc; + GList *ll; + + while ((ifc = g_queue_pop_head(&all_local_interfaces))) { + free(ifc->ice_foundation.s); + g_slice_free1(sizeof(*ifc), ifc); + } + + ll = g_hash_table_get_values(__logical_intf_name_family_hash); + for (GList *l = ll; l; l = l->next) { + struct logical_intf *lif = l->data; + g_hash_table_destroy(lif->addr_hash); + g_hash_table_destroy(lif->rr_specs); + g_queue_clear(&lif->list); + g_slice_free1(sizeof(*lif), lif); + } + g_list_free(ll); + g_hash_table_destroy(__logical_intf_name_family_hash); + + ll = g_hash_table_get_values(__local_intf_addr_type_hash); + for (GList *l = ll; l; l = l->next) { + GList *k = l->data; + g_list_free(k); + } + g_list_free(ll); + g_hash_table_destroy(__local_intf_addr_type_hash); + + ll = g_hash_table_get_values(__intf_spec_addr_type_hash); + for (GList *l = ll; l; l = l->next) { + struct intf_spec *spec = l->data; + struct port_pool *pp = &spec->port_pool; + g_queue_clear(&pp->free_list); + g_slice_free1(sizeof(*spec), spec); + } + g_list_free(ll); + g_hash_table_destroy(__intf_spec_addr_type_hash); + + ll = g_hash_table_get_values(__logical_intf_name_family_rr_hash); + for (GList *l = ll; l; l = l->next) { + struct intf_rr *rr = l->data; + g_queue_clear(&rr->logical_intfs); + g_slice_free1(sizeof(*rr), rr); + } + g_list_free(ll); + g_hash_table_destroy(__logical_intf_name_family_rr_hash); + + for (int i = 0; i < G_N_ELEMENTS(__preferred_lists_for_family); i++) + g_queue_clear(&__preferred_lists_for_family[i]); +} diff --git a/include/media_socket.h b/include/media_socket.h index 58dfab330..19b5c3a58 100644 --- a/include/media_socket.h +++ b/include/media_socket.h @@ -147,6 +147,7 @@ extern GQueue all_local_interfaces; // read-only during runtime void interfaces_init(GQueue *interfaces); +void interfaces_free(void); struct logical_intf *get_logical_interface(const str *name, sockfamily_t *fam, int num_ports); struct local_intf *get_interface_address(const struct logical_intf *lif, sockfamily_t *fam);