diff --git a/daemon/call_interfaces.c b/daemon/call_interfaces.c index 4e2c0a1e1..9abfab6dd 100644 --- a/daemon/call_interfaces.c +++ b/daemon/call_interfaces.c @@ -2102,6 +2102,27 @@ out: #endif } +void call_interfaces_free() { + if (info_re) { + pcre_free(info_re); + info_re = NULL; + } + + if (streams_re) { + pcre_free(streams_re); + streams_re= NULL; + } + + if (info_ree) { + pcre_free_study(info_ree); + info_ree = NULL; + } + + if (streams_ree) { + pcre_free_study(streams_ree); + streams_ree = NULL; + } +} int call_interfaces_init() { const char *errptr; diff --git a/daemon/ice.c b/daemon/ice.c index ef7b5ac9d..b1b4d8dbc 100644 --- a/daemon/ice.c +++ b/daemon/ice.c @@ -554,6 +554,10 @@ void ice_init(void) { timerthread_init(&ice_agents_timer_thread, ice_agents_timer_run); } +void ice_free(void) { + timerthread_free(&ice_agents_timer_thread); +} + static void __fail_pair(struct ice_candidate_pair *pair) { diff --git a/daemon/jitter_buffer.c b/daemon/jitter_buffer.c index 410cbcb78..811247cc4 100644 --- a/daemon/jitter_buffer.c +++ b/daemon/jitter_buffer.c @@ -23,6 +23,11 @@ void jitter_buffer_init(void) { timerthread_init(&jitter_buffer_thread, timerthread_queue_run); } +void jitter_buffer_init_free(void) { + ilog(LOG_DEBUG, "jitter_buffer_free"); + timerthread_free(&jitter_buffer_thread); +} + static void jitter_buffer_flush(struct jitter_buffer *jb) { mutex_unlock(&jb->lock); timerthread_queue_flush_data(&jb->ttq); diff --git a/daemon/main.c b/daemon/main.c index 71646cf8d..e80bf72ba 100644 --- a/daemon/main.c +++ b/daemon/main.c @@ -960,16 +960,26 @@ int main(int argc, char **argv) { ilog(LOG_INFO, "Version %s shutting down", RTPENGINE_VERSION); + unfill_initial_rtpe_cfg(&initial_rtpe_config); + + call_free(); + + jitter_buffer_init_free(); + media_player_free(); + codeclib_free(); + statistics_free(); + call_interfaces_free(); + interfaces_free(); + ice_free(); + dtls_cert_free(); + redis_close(rtpe_redis); redis_close(rtpe_redis_write); redis_close(rtpe_redis_notify); - dtls_cert_free(); - - unfill_initial_rtpe_cfg(&initial_rtpe_config); options_free(); - call_free(); - interfaces_free(); + + log_free(); obj_release(rtpe_cli); obj_release(rtpe_udp); diff --git a/daemon/media_player.c b/daemon/media_player.c index ef69f222d..a9bd95cbe 100644 --- a/daemon/media_player.c +++ b/daemon/media_player.c @@ -753,6 +753,13 @@ void media_player_init(void) { timerthread_init(&send_timer_thread, timerthread_queue_run); } +void media_player_free(void) { +#ifdef WITH_TRANSCODING + timerthread_free(&media_player_thread); +#endif + timerthread_free(&send_timer_thread); +} + #ifdef WITH_TRANSCODING void media_player_loop(void *p) { diff --git a/daemon/statistics.c b/daemon/statistics.c index ffc61ae73..fc83d6470 100644 --- a/daemon/statistics.c +++ b/daemon/statistics.c @@ -634,6 +634,26 @@ void statistics_free_metrics(GQueue **q) { *q = NULL; } +void statistics_free() { + mutex_destroy(&rtpe_totalstats.total_average_lock); + mutex_destroy(&rtpe_totalstats_interval.total_average_lock); + mutex_destroy(&rtpe_totalstats_interval.managed_sess_lock); + mutex_destroy(&rtpe_totalstats_interval.total_calls_duration_lock); + + mutex_destroy(&rtpe_totalstats_lastinterval_lock); + + mutex_destroy(&rtpe_totalstats_interval.offer.lock); + mutex_destroy(&rtpe_totalstats_interval.answer.lock); + mutex_destroy(&rtpe_totalstats_interval.delete.lock); + + mutex_destroy(&rtpe_totalstats_interval.offers_ps.lock); + mutex_destroy(&rtpe_totalstats_interval.answers_ps.lock); + mutex_destroy(&rtpe_totalstats_interval.deletes_ps.lock); + + mutex_destroy(&rtpe_codec_stats_lock); + g_hash_table_destroy(rtpe_codec_stats); +} + void statistics_init() { mutex_init(&rtpe_totalstats.total_average_lock); mutex_init(&rtpe_totalstats_interval.total_average_lock); diff --git a/daemon/timerthread.c b/daemon/timerthread.c index 473b15daa..8e8a972b3 100644 --- a/daemon/timerthread.c +++ b/daemon/timerthread.c @@ -14,6 +14,11 @@ void timerthread_init(struct timerthread *tt, void (*func)(void *)) { tt->func = func; } +void timerthread_free(struct timerthread *tt) { + g_tree_destroy(tt->tree); + mutex_destroy(&tt->lock); +} + void timerthread_run(void *p) { struct timerthread *tt = p; diff --git a/include/call_interfaces.h b/include/call_interfaces.h index ba1a41666..8656896b4 100644 --- a/include/call_interfaces.h +++ b/include/call_interfaces.h @@ -139,6 +139,7 @@ void ng_call_stats(struct call *call, const str *fromtag, const str *totag, benc struct call_stats *totals); int call_interfaces_init(void); +void call_interfaces_free(void); #endif diff --git a/include/ice.h b/include/ice.h index 74161e5ea..059b6af16 100644 --- a/include/ice.h +++ b/include/ice.h @@ -141,6 +141,7 @@ extern const char * const ice_type_strings[]; void ice_init(void); +void ice_free(void); enum ice_candidate_type ice_candidate_type(const str *s); int ice_has_related(enum ice_candidate_type); diff --git a/include/jitter_buffer.h b/include/jitter_buffer.h index d715941ac..80a11e986 100644 --- a/include/jitter_buffer.h +++ b/include/jitter_buffer.h @@ -42,6 +42,7 @@ struct jitter_buffer { }; void jitter_buffer_init(void); +void jitter_buffer_init_free(void); struct jitter_buffer *jitter_buffer_new(struct call *); void jitter_buffer_free(struct jitter_buffer **); diff --git a/include/media_player.h b/include/media_player.h index 65cde1c82..517dc4154 100644 --- a/include/media_player.h +++ b/include/media_player.h @@ -87,6 +87,7 @@ void media_player_add_packet(struct media_player *mp, char *buf, size_t len, long long us_dur, unsigned long long pts); void media_player_init(void); +void media_player_free(void); void media_player_loop(void *); struct send_timer *send_timer_new(struct packet_stream *); diff --git a/include/statistics.h b/include/statistics.h index 17d211c0c..2c3f6175a 100644 --- a/include/statistics.h +++ b/include/statistics.h @@ -130,5 +130,6 @@ void statistics_free_metrics(GQueue **); const char *statistics_ng(bencode_item_t *input, bencode_item_t *output); void statistics_init(void); +void statistics_free(void); #endif /* STATISTICS_H_ */ diff --git a/include/timerthread.h b/include/timerthread.h index 9f344ce63..ebb72556f 100644 --- a/include/timerthread.h +++ b/include/timerthread.h @@ -41,6 +41,7 @@ struct timerthread_queue_entry { void timerthread_init(struct timerthread *, void (*)(void *)); +void timerthread_free(struct timerthread *); void timerthread_run(void *); void timerthread_obj_schedule_abs_nl(struct timerthread_obj *, const struct timeval *); diff --git a/lib/codeclib.c b/lib/codeclib.c index 3df3f57e4..c34cce3e8 100644 --- a/lib/codeclib.c +++ b/lib/codeclib.c @@ -759,6 +759,12 @@ static void avc_def_init(codec_def_t *def) { } } +void codeclib_free(void) { + g_hash_table_destroy(codecs_ht); + g_hash_table_destroy(codecs_ht_by_av); + avformat_network_deinit(); +} + void codeclib_init(int print) { #if LIBAVCODEC_VERSION_INT < AV_VERSION_INT(58, 9, 100) av_register_all(); diff --git a/lib/codeclib.h b/lib/codeclib.h index 5b9dda5af..8ede0bc7d 100644 --- a/lib/codeclib.h +++ b/lib/codeclib.h @@ -211,6 +211,7 @@ struct packet_sequencer_s { void codeclib_init(int); +void codeclib_free(void); const codec_def_t *codec_find(const str *name, enum media_type); diff --git a/lib/loglib.c b/lib/loglib.c index 6f1e5d1e3..13f9bcd0d 100644 --- a/lib/loglib.c +++ b/lib/loglib.c @@ -230,6 +230,12 @@ void log_init(const char *handle) { openlog(handle, LOG_PID | LOG_NDELAY, ilog_facility); } +void log_free() { + g_hash_table_destroy(__log_limiter); + g_string_chunk_free(__log_limiter_strings); + pthread_mutex_destroy(&__log_limiter_lock); +} + int parse_log_facility(const char *name, int *dst) { int i; for (i = 0 ; _facilitynames[i].c_name; i++) { diff --git a/lib/loglib.h b/lib/loglib.h index e40e5d358..efecb4262 100644 --- a/lib/loglib.h +++ b/lib/loglib.h @@ -23,6 +23,7 @@ void print_available_log_facilities (void); void log_to_stderr(int facility_priority, const char *format, ...) __attribute__ ((format (printf, 2, 3))); void log_init(const char *); +void log_free(void); void __vpilog(int prio, const char *prefix, const char *fmt, va_list); void __ilog_np(int prio, const char *format, ...) __attribute__ ((format (printf, 2, 3)));