From: Jaroslav Kysela Date: Wed, 7 Nov 2018 15:10:06 +0000 (+0100) Subject: satip server: fix memory leak for the slave service subscription, fixes #5314 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=905bf283a2fee9348403c95dc9ad3ca4a9c46929;p=thirdparty%2Ftvheadend.git satip server: fix memory leak for the slave service subscription, fixes #5314 --- diff --git a/src/dvr/dvr_rec.c b/src/dvr/dvr_rec.c index fe1b96a07..8add06be6 100644 --- a/src/dvr/dvr_rec.c +++ b/src/dvr/dvr_rec.c @@ -138,13 +138,13 @@ dvr_rec_subscribe(dvr_entry_t *de) pro = de->de_config->dvr_profile; prch = malloc(sizeof(*prch)); - profile_chain_init(prch, pro, de->de_channel); + profile_chain_init(prch, pro, de->de_channel, 1); if (profile_chain_open(prch, &de->de_config->dvr_muxcnf, NULL, 0, 0)) { profile_chain_close(prch); tvherror(LS_DVR, "unable to create new channel streaming chain '%s' for '%s', using default", profile_get_name(pro), channel_get_name(de->de_channel, channel_blank_name)); pro = profile_find_by_name(NULL, NULL); - profile_chain_init(prch, pro, de->de_channel); + profile_chain_init(prch, pro, de->de_channel, 1); if (profile_chain_open(prch, &de->de_config->dvr_muxcnf, NULL, 0, 0)) { tvherror(LS_DVR, "unable to create channel streaming default chain '%s' for '%s'", profile_get_name(pro), channel_get_name(de->de_channel, channel_blank_name)); diff --git a/src/htsp_server.c b/src/htsp_server.c index bc1ce16ce..aa5f02b39 100644 --- a/src/htsp_server.c +++ b/src/htsp_server.c @@ -2548,7 +2548,7 @@ htsp_method_subscribe(htsp_connection_t *htsp, htsmsg_t *in) pro = profile_find_by_list(htsp->htsp_granted_access->aa_profiles, profile_id, "htsp", SUBSCRIPTION_PACKET | SUBSCRIPTION_HTSP); - profile_chain_init(&hs->hs_prch, pro, ch); + profile_chain_init(&hs->hs_prch, pro, ch, 1); if (profile_chain_work(&hs->hs_prch, &hs->hs_input, timeshiftPeriod, 0)) { tvherror(LS_HTSP, "unable to create profile chain '%s'", profile_get_name(pro)); profile_chain_close(&hs->hs_prch); diff --git a/src/profile.c b/src/profile.c index 4f710b07d..f43944774 100644 --- a/src/profile.c +++ b/src/profile.c @@ -1020,15 +1020,17 @@ profile_sharer_destroy(profile_chain_t *prch) * */ void -profile_chain_init(profile_chain_t *prch, profile_t *pro, void *id) +profile_chain_init(profile_chain_t *prch, profile_t *pro, void *id, int queue) { memset(prch, 0, sizeof(*prch)); if (pro) profile_grab(pro); prch->prch_pro = pro; prch->prch_id = id; - streaming_queue_init(&prch->prch_sq, 0, 0); - prch->prch_sq_used = 1; + if (queue) { + streaming_queue_init(&prch->prch_sq, 0, 0); + prch->prch_sq_used = 1; + } LIST_INSERT_HEAD(&profile_chains, prch, prch_link); prch->prch_linked = 1; prch->prch_stop = 1; diff --git a/src/profile.h b/src/profile.h index 0c6e623d8..196c612db 100644 --- a/src/profile.h +++ b/src/profile.h @@ -182,7 +182,7 @@ int profile_chain_open(profile_chain_t *prch, muxer_config_t *m_cfg, muxer_hints_t *hints, int flags, size_t qsize); -void profile_chain_init(profile_chain_t *prch, profile_t *pro, void *id); +void profile_chain_init(profile_chain_t *prch, profile_t *pro, void *id, int queue); int profile_chain_raw_open(profile_chain_t *prch, void *id, size_t qsize, int muxer); void profile_chain_close(profile_chain_t *prch); int profile_chain_weight(profile_chain_t *prch, int custom); diff --git a/src/satip/rtsp.c b/src/satip/rtsp.c index 6aa2c7527..ec1685899 100644 --- a/src/satip/rtsp.c +++ b/src/satip/rtsp.c @@ -391,9 +391,7 @@ rtsp_slave_add pthread_mutex_unlock(&master->s_stream_mutex); master->s_link(master, slave); sub->service = slave; - profile_chain_init(&sub->prch, NULL, NULL); - sub->prch.prch_st = &sub->prch.prch_sq.sq_st; - sub->prch.prch_id = slave; + profile_chain_init(&sub->prch, NULL, slave, 0); snprintf(buf, sizeof(buf), "SAT>IP Slave/%s", slave->s_nicename); sub->ths = subscription_create_from_service(&sub->prch, NULL, SUBSCRIPTION_NONE, diff --git a/src/service_mapper.c b/src/service_mapper.c index 122b3a19f..84e778731 100644 --- a/src/service_mapper.c +++ b/src/service_mapper.c @@ -369,7 +369,7 @@ service_mapper_thread ( void *aux ) const char *err = NULL; uint64_t timeout, timeout_other; - profile_chain_init(&prch, NULL, NULL); + profile_chain_init(&prch, NULL, NULL, 1); prch.prch_st = &prch.prch_sq.sq_st; sq = &prch.prch_sq; diff --git a/src/subscriptions.c b/src/subscriptions.c index 8c977725c..032f484a2 100644 --- a/src/subscriptions.c +++ b/src/subscriptions.c @@ -916,7 +916,7 @@ subscription_create_from_channel(profile_chain_t *prch, const char *client, int *error) { - assert(prch->prch_st); + assert(flags == SUBSCRIPTION_NONE || prch->prch_st); return subscription_create_from_channel_or_service (prch, ti, weight, name, flags, hostname, username, client, error, NULL); @@ -936,7 +936,7 @@ subscription_create_from_service(profile_chain_t *prch, const char *client, int *error) { - assert(prch->prch_st); + assert(flags == SUBSCRIPTION_NONE || prch->prch_st); return subscription_create_from_channel_or_service (prch, ti, weight, name, flags, hostname, username, client, error, prch->prch_id); diff --git a/src/webui/webui.c b/src/webui/webui.c index feb455096..942a104f9 100644 --- a/src/webui/webui.c +++ b/src/webui/webui.c @@ -1172,7 +1172,7 @@ http_stream_service(http_connection_t *hc, service_t *service, int weight) hints = muxer_hints_create(http_arg_get(&hc->hc_args, "User-Agent")); - profile_chain_init(&prch, pro, service); + profile_chain_init(&prch, pro, service, 1); if (!profile_chain_open(&prch, NULL, hints, 0, qsize)) { s = subscription_create_from_service(&prch, NULL, weight, "HTTP", @@ -1314,7 +1314,7 @@ http_stream_channel(http_connection_t *hc, channel_t *ch, int weight) hints = muxer_hints_create(http_arg_get(&hc->hc_args, "User-Agent")); - profile_chain_init(&prch, pro, ch); + profile_chain_init(&prch, pro, ch, 1); if (!profile_chain_open(&prch, NULL, hints, 0, qsize)) { s = subscription_create_from_channel(&prch,