]> git.ipfire.org Git - thirdparty/tvheadend.git/commitdiff
dvr: cleanup the error path in dvr_rec_subscribe()
authorJaroslav Kysela <perex@perex.cz>
Mon, 22 Oct 2018 06:48:20 +0000 (08:48 +0200)
committerJaroslav Kysela <perex@perex.cz>
Mon, 22 Oct 2018 06:48:20 +0000 (08:48 +0200)
src/dvr/dvr_rec.c
src/profile.c

index e8173045c7335be39449c18b12b86ba2b0bb4664..b7f47220be11f038bcc5bbfdb15732f7d964b9f5 100644 (file)
@@ -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;
 }
 
 /**
index bf542ee83a4a0762366c571d0e901854653ed684..00570b9fa55cfcaa857cafb85d1ffa1e5bda0620 100644 (file)
@@ -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