From c70b3f6369bda77406dade083ca6555549622ce2 Mon Sep 17 00:00:00 2001 From: Richard Fuchs Date: Wed, 22 Jan 2020 12:48:32 -0500 Subject: [PATCH] TT#74651 fix several mem/resource leaks fix cleanup being skipped on redis slaves fixes an SDES related Redis mem leak adds a hash for the ports free list to avoid duplicate entries fixes #898 Change-Id: I34aad67290ff5ef8824142682aac03cb600d0ecb --- daemon/call.c | 30 +++++++++++++++++++++++------- daemon/media_socket.c | 7 ++++++- daemon/redis.c | 1 + include/media_socket.h | 1 + 4 files changed, 31 insertions(+), 8 deletions(-) diff --git a/daemon/call.c b/daemon/call.c index a21fc84c6..62c4d5fa6 100644 --- a/daemon/call.c +++ b/daemon/call.c @@ -2152,11 +2152,15 @@ void call_destroy(struct call *c) { if (!IS_OWN_CALL(c)) goto no_stats_output; + ///// stats output + ilog(LOG_INFO, "Final packet stats:"); for (l = c->monologues.head; l; l = l->next) { ml = l->data; + // stats output only - no cleanups + ilog(LOG_INFO, "--- Tag '" STR_FORMAT_M "'%s"STR_FORMAT"%s, created " "%u:%02u ago for branch '" STR_FORMAT_M "', in dialogue with '" STR_FORMAT_M "'", STR_FMT_M(&ml->tag), @@ -2174,6 +2178,8 @@ void call_destroy(struct call *c) { for (k = ml->medias.head; k; k = k->next) { md = k->data; + // stats output only - no cleanups + rtp_pt = __rtp_stats_codec(md); #define MLL_PREFIX "------ Media #%u ("STR_FORMAT" over %s) using " /* media log line prefix */ #define MLL_COMMON /* common args */ \ @@ -2189,7 +2195,7 @@ void call_destroy(struct call *c) { for (o = md->streams.head; o; o = o->next) { ps = o->data; - send_timer_put(&ps->send_timer); + // stats output only - no cleanups if (PS_ISSET(ps, FALLBACK_RTCP)) continue; @@ -2210,20 +2216,16 @@ void call_destroy(struct call *c) { rtpe_now.tv_sec - atomic64_get(&ps->last_packet)); statistics_update_totals(ps); - } - - ice_shutdown(&md->ice_agent); } - - media_player_stop(ml->player); - media_player_put(&ml->player); } k = g_hash_table_get_values(c->ssrc_hash->ht); for (l = k; l; l = l->next) { struct ssrc_entry_call *se = l->data; + // stats output only - no cleanups + if (!se->stats_blocks.length || !se->lowest_mos || !se->highest_mos) continue; @@ -2245,6 +2247,8 @@ void call_destroy(struct call *c) { g_list_free(k); no_stats_output: + // cleanups + statistics_update_oneway(c); cdr_update_entry(c); @@ -2252,6 +2256,7 @@ no_stats_output: for (l = c->streams.head; l; l = l->next) { ps = l->data; + send_timer_put(&ps->send_timer); __unkernelize(ps); dtls_shutdown(ps); ps->selected_sfd = NULL; @@ -2262,6 +2267,17 @@ no_stats_output: ps->rtcp_sink = NULL; } + for (l = c->medias.head; l; l = l->next) { + md = l->data; + ice_shutdown(&md->ice_agent); + } + + for (l = c->monologues.head; l; l = l->next) { + ml = l->data; + media_player_stop(ml->player); + media_player_put(&ml->player); + } + while (c->stream_fds.head) { sfd = g_queue_pop_head(&c->stream_fds); poller_del_item(rtpe_poller, sfd->socket.fd); diff --git a/daemon/media_socket.c b/daemon/media_socket.c index c6c3df3e9..a29c1993a 100644 --- a/daemon/media_socket.c +++ b/daemon/media_socket.c @@ -760,7 +760,10 @@ static void release_port(socket_t *r, struct intf_spec *spec) { g_atomic_int_inc(&pp->free_ports); if ((port & 1) == 0) { mutex_lock(&pp->free_list_lock); - g_queue_push_tail(&pp->free_list, GUINT_TO_POINTER(port)); + if (!bit_array_isset(pp->free_list_used, port)) { + g_queue_push_tail(&pp->free_list, GUINT_TO_POINTER(port)); + bit_array_set(pp->free_list_used, port); + } mutex_unlock(&pp->free_list_lock); } } else { @@ -807,6 +810,8 @@ int __get_consecutive_ports(GQueue *out, unsigned int num_ports, unsigned int wa __C_DBG("port %d is USED in port pool", port); mutex_lock(&pp->free_list_lock); unsigned int fport = GPOINTER_TO_UINT(g_queue_pop_head(&pp->free_list)); + if (fport) + bit_array_clear(pp->free_list_used, fport); mutex_unlock(&pp->free_list_lock); if (fport) { port = fport; diff --git a/daemon/redis.c b/daemon/redis.c index be496325b..578f550c2 100644 --- a/daemon/redis.c +++ b/daemon/redis.c @@ -1105,6 +1105,7 @@ static int redis_hash_get_sdes_params(GQueue *out, const struct redis_hash *h, c return -1; } + g_queue_push_tail(out, cps); snprintf(key, sizeof(key), "%s-%u", k, iter++); kk = key; } diff --git a/include/media_socket.h b/include/media_socket.h index 438e73f25..967a96cf9 100644 --- a/include/media_socket.h +++ b/include/media_socket.h @@ -78,6 +78,7 @@ struct port_pool { mutex_t free_list_lock; GQueue free_list; + BIT_ARRAY_DECLARE(free_list_used, 0x10000); }; struct intf_address { socktype_t *type;