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-Tag: v4.2.8~28 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=2905738b7c2591aeef629e905c232ac80990d3c1;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 28a6f9fc1..a3291d676 100644 --- a/src/dvr/dvr_rec.c +++ b/src/dvr/dvr_rec.c @@ -118,13 +118,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, 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)); 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, 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)); diff --git a/src/htsp_server.c b/src/htsp_server.c index f349543e8..9ee8d01a9 100644 --- a/src/htsp_server.c +++ b/src/htsp_server.c @@ -2490,7 +2490,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 a8006b730..05c181b89 100644 --- a/src/profile.c +++ b/src/profile.c @@ -866,15 +866,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 bcb8fd8df..f4b795f54 100644 --- a/src/profile.h +++ b/src/profile.h @@ -170,7 +170,7 @@ profile_chain_reopen(profile_chain_t *prch, int profile_chain_open(profile_chain_t *prch, muxer_config_t *m_cfg, 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 57a999ad6..701dd9a2d 100644 --- a/src/satip/rtsp.c +++ b/src/satip/rtsp.c @@ -332,9 +332,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 5267d3a94..c445c1d8c 100644 --- a/src/service_mapper.c +++ b/src/service_mapper.c @@ -303,7 +303,7 @@ service_mapper_thread ( void *aux ) const char *err = NULL; uint64_t timeout; - 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 f8c2a587c..152e73db4 100644 --- a/src/subscriptions.c +++ b/src/subscriptions.c @@ -909,7 +909,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); @@ -929,7 +929,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 12b965230..5a57df9b0 100644 --- a/src/webui/webui.c +++ b/src/webui/webui.c @@ -1165,7 +1165,7 @@ http_stream_service(http_connection_t *hc, service_t *service, int weight) else qsize = 1500000; - profile_chain_init(&prch, pro, service); + profile_chain_init(&prch, pro, service, 1); if (!profile_chain_open(&prch, NULL, 0, qsize)) { s = subscription_create_from_service(&prch, NULL, weight, "HTTP", @@ -1304,7 +1304,7 @@ http_stream_channel(http_connection_t *hc, channel_t *ch, int weight) else qsize = 1500000; - profile_chain_init(&prch, pro, ch); + profile_chain_init(&prch, pro, ch, 1); if (!profile_chain_open(&prch, NULL, 0, qsize)) { s = subscription_create_from_channel(&prch,