From: Jaroslav Kysela Date: Mon, 22 Oct 2018 06:48:20 +0000 (+0200) Subject: dvr: cleanup the error path in dvr_rec_subscribe() X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=1f74101898cedf5eaaee5cd8195d044250d92100;p=thirdparty%2Ftvheadend.git dvr: cleanup the error path in dvr_rec_subscribe() --- diff --git a/src/dvr/dvr_rec.c b/src/dvr/dvr_rec.c index e8173045c..b7f47220b 100644 --- a/src/dvr/dvr_rec.c +++ b/src/dvr/dvr_rec.c @@ -83,11 +83,11 @@ dvr_rec_subscribe(dvr_entry_t *de) char buf[100]; int weight; profile_t *pro; - profile_chain_t *prch; + profile_chain_t *prch = NULL; struct sockaddr_storage sa; access_t *aa; uint32_t rec_count, net_count; - int pri, c1, c2; + int ret = 0, pri, c1, c2; struct stat st; assert(de->de_s == NULL); @@ -102,15 +102,16 @@ dvr_rec_subscribe(dvr_entry_t *de) snprintf(buf, sizeof(buf), "DVR: %s", lang_str_get(de->de_title, NULL)); - if (de->de_owner && de->de_owner[0] != '\0') + if (de->de_owner && de->de_owner[0] != '\0') { aa = access_get_by_username(de->de_owner); - else if (de->de_creator && de->de_creator[0] != '\0' && - tcp_get_ip_from_str(de->de_creator, &sa) != NULL) + } else if (de->de_creator && de->de_creator[0] != '\0' && + tcp_get_ip_from_str(de->de_creator, &sa) != NULL) { aa = access_get_by_addr(&sa); - else { + } else { tvherror(LS_DVR, "unable to find access (owner '%s', creator '%s')", de->de_owner, de->de_creator); - return -EPERM; + ret = -EPERM; + goto _return; } if (aa->aa_conn_limit || aa->aa_conn_limit_dvr) { @@ -124,15 +125,15 @@ dvr_rec_subscribe(dvr_entry_t *de) "(limit %u, dvr limit %u, active DVR %u, streaming %u)", aa->aa_username ?: "", aa->aa_representative ?: "", aa->aa_conn_limit, aa->aa_conn_limit_dvr, rec_count, net_count); - access_destroy(aa); - return -EOVERFLOW; + ret = -EOVERFLOW; + goto _return; } } if(stat(de->de_config->dvr_storage, &st) || !S_ISDIR(st.st_mode)) { tvherror(LS_DVR, "the directory '%s' is not accessible", de->de_config->dvr_storage); - access_destroy(aa); - return -EIO; + ret = -EIO; + goto _return; } pro = de->de_config->dvr_profile; @@ -147,10 +148,8 @@ dvr_rec_subscribe(dvr_entry_t *de) 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)); - profile_chain_close(prch); - free(prch); - access_destroy(aa); - return -EINVAL; + ret = -EINVAL; + goto _return; } } @@ -160,10 +159,8 @@ dvr_rec_subscribe(dvr_entry_t *de) if (de->de_s == NULL) { tvherror(LS_DVR, "unable to create new channel subcription for '%s' profile '%s'", channel_get_name(de->de_channel, channel_blank_name), profile_get_name(pro)); - profile_chain_close(prch); - free(prch); - access_destroy(aa); - return -EINVAL; + ret = -EINVAL; + goto _return; } de->de_chain = prch; @@ -175,8 +172,15 @@ dvr_rec_subscribe(dvr_entry_t *de) dvr_spawn_cmd(de, de->de_config->dvr_preproc, NULL, 1); if (de->de_config->dvr_fetch_artwork) dvr_spawn_fetch_artwork(de); + access_destroy(aa); - return 0; + return ret; + +_return: + profile_chain_close(prch); + free(prch); + access_destroy(aa); + return ret; } /** diff --git a/src/profile.c b/src/profile.c index bf542ee83..00570b9fa 100644 --- a/src/profile.c +++ b/src/profile.c @@ -1143,6 +1143,9 @@ int profile_chain_weight(profile_chain_t *prch, int custom) void profile_chain_close(profile_chain_t *prch) { + if (prch == NULL) + return; + profile_sharer_destroy(prch); #if ENABLE_TIMESHIFT