From a7faec05d904ee0cfd542e3004f83d1a00310573 Mon Sep 17 00:00:00 2001 From: Vito Caputo Date: Mon, 2 May 2022 10:30:10 -0700 Subject: modules/rtv: plug big channel leak on context destroy There's more to cleanup in rtv destruction, but this is the major one. --- src/modules/rtv/rtv.c | 32 ++++++++++++++++++++++---------- 1 file changed, 22 insertions(+), 10 deletions(-) (limited to 'src/modules/rtv') diff --git a/src/modules/rtv/rtv.c b/src/modules/rtv/rtv.c index 2500305..a9bf8f6 100644 --- a/src/modules/rtv/rtv.c +++ b/src/modules/rtv/rtv.c @@ -110,6 +110,22 @@ static void randomize_channels(rtv_context_t *ctxt) } +static void cleanup_channel(rtv_context_t *ctxt) +{ + if (!ctxt->channel) + return; + + ctxt->channel->cumulative_time = 0; + + ctxt->channel->module_ctxt = til_module_destroy_context(ctxt->channel->module, ctxt->channel->module_ctxt); + + free(ctxt->channel->settings_as_arg); + ctxt->channel->settings_as_arg = NULL; + + ctxt->caption = ctxt->channel->caption = txt_free(ctxt->channel->caption); +} + + static void setup_next_channel(rtv_context_t *ctxt, unsigned ticks) { time_t now = time(NULL); @@ -119,16 +135,8 @@ static void setup_next_channel(rtv_context_t *ctxt, unsigned ticks) */ if (ctxt->channel) { ctxt->channel->cumulative_time += now - ctxt->channel->last_on_time; - if (ctxt->channel->cumulative_time >= ctxt->context_duration) { - ctxt->channel->cumulative_time = 0; - - ctxt->channel->module_ctxt = til_module_destroy_context(ctxt->channel->module, ctxt->channel->module_ctxt); - - free(ctxt->channel->settings_as_arg); - ctxt->channel->settings_as_arg = NULL; - - ctxt->caption = ctxt->channel->caption = txt_free(ctxt->channel->caption); - } + if (ctxt->channel->cumulative_time >= ctxt->context_duration) + cleanup_channel(ctxt); } if (!ctxt->n_channels || @@ -250,6 +258,10 @@ static void * rtv_create_context(unsigned ticks, unsigned n_cpus, til_setup_t *s static void rtv_destroy_context(void *context) { + rtv_context_t *ctxt = context; + + /* TODO FIXME: cleanup better, snow module etc */ + cleanup_channel(ctxt); free(context); } -- cgit v1.2.1