]> git.ipfire.org Git - thirdparty/tvheadend.git/commitdiff
change semantics for transport stop so we dont leak memory
authorAndreas Öman <andreas@lonelycoder.com>
Wed, 28 Nov 2007 09:16:16 +0000 (09:16 +0000)
committerAndreas Öman <andreas@lonelycoder.com>
Wed, 28 Nov 2007 09:16:16 +0000 (09:16 +0000)
avgen.c
dvb_dvr.c
subscriptions.c
transports.c
transports.h
v4l.c

diff --git a/avgen.c b/avgen.c
index 94910e5d2343de54a3f217da2a86358367b0cd04..b64df32058fb5b03d9b8c9a505213e5466d28c20 100644 (file)
--- a/avgen.c
+++ b/avgen.c
@@ -142,7 +142,6 @@ avgen_stop_feed(th_transport_t *t)
   free(avg);
 
   t->tht_status = TRANSPORT_IDLE;
-  transport_flush_subscribers(t);
 }
 
 
index edf4dca83769ee7aea8b5cab49da90d31d08b2a9..dd52c9722745946bb8fc6e251c139beb95f6cfa9 100644 (file)
--- a/dvb_dvr.c
+++ b/dvb_dvr.c
@@ -109,7 +109,7 @@ dvb_adapter_clean(th_dvb_adapter_t *tda)
   th_transport_t *t;
   
   while((t = LIST_FIRST(&tda->tda_transports)) != NULL)
-    dvb_stop_feed(t);
+    transport_stop(t, 1);
 }
 
 
@@ -129,7 +129,6 @@ dvb_stop_feed(th_transport_t *t)
     st->st_demuxer_fd = -1;
   }
   t->tht_status = TRANSPORT_IDLE;
-  transport_flush_subscribers(t);
 }
 
 
index 8c88e319cee1bc09dc2273af7bfb978d5abc2258..fe55801481678a0e7a72781787278297ac10dabe 100644 (file)
@@ -102,7 +102,7 @@ subscription_unsubscribe(th_subscription_t *s)
 
   if(t != NULL) {
     subscription_stop(s);
-    transport_purge(t);
+    transport_stop(t, 0);
   }
 
   free(s->ths_title);
index 20cdbee54e41e4ab793cce5bacd1ff8e72e4d207..623724c5072be213e1fef730b2b8af487019f54a 100644 (file)
@@ -58,13 +58,19 @@ static dtimer_t transport_monitor_timer;
 
 
 void
-transport_purge(th_transport_t *t)
+transport_stop(th_transport_t *t, int flush_subscriptions)
 {
+  th_subscription_t *s;
   th_stream_t *st;
   th_pkt_t *pkt;
 
-  if(LIST_FIRST(&t->tht_subscriptions))
-    return;
+  if(flush_subscriptions) {
+    while((s = LIST_FIRST(&t->tht_subscriptions)) != NULL)
+      subscription_stop(s);
+  } else {
+    if(LIST_FIRST(&t->tht_subscriptions))
+      return;
+  }
 
   t->tht_stop_feed(t);
 
@@ -83,6 +89,9 @@ transport_purge(th_transport_t *t)
     if(st->st_ctx != NULL)
       avcodec_close(st->st_ctx);
 
+    st->st_parser = NULL;
+    st->st_ctx = NULL;
+
     /* Clear reassembly buffer */
 
     free(st->st_buffer);
@@ -136,6 +145,11 @@ transport_start(th_transport_t *t, unsigned int weight)
   AVCodec *c;
   enum CodecID id;
 
+  assert(t->tht_status != TRANSPORT_RUNNING);
+
+  if(t->tht_start_feed(t, weight, TRANSPORT_RUNNING))
+    return -1;
+
   t->tht_monitor_suspend = 10;
   t->tht_dts_start = AV_NOPTS_VALUE;
 
@@ -155,8 +169,8 @@ transport_start(th_transport_t *t, unsigned int weight)
     default:               id = CODEC_ID_NONE;       break;
     }
     
-    st->st_ctx = NULL;
-    st->st_parser = NULL;
+    assert(st->st_ctx == NULL);
+    assert(st->st_parser == NULL);
 
     if(id != CODEC_ID_NONE) {
       c = avcodec_find_decoder(id);
@@ -167,8 +181,7 @@ transport_start(th_transport_t *t, unsigned int weight)
       }
     }
   }
-  
-  return t->tht_start_feed(t, weight, TRANSPORT_RUNNING);
+  return 0;
 }
 
 
index 7a2bb999c7b73604e2636b12aceba0a554a16afa..f4f29e0c7403a3668d2bce5612f9ef232d659255 100644 (file)
@@ -23,7 +23,7 @@
 
 unsigned int transport_compute_weight(struct th_transport_list *head);
 
-void transport_flush_subscribers(th_transport_t *t);
+void transport_stop(th_transport_t *t, int flush_subscriptions);
 
 void transport_monitor_init(th_transport_t *t);
 
@@ -33,10 +33,7 @@ void transport_link(th_transport_t *t, th_channel_t *ch);
 
 th_transport_t *transport_find(th_channel_t *ch, unsigned int weight);
 
-void transport_purge(th_transport_t *t);
-
 th_stream_t *transport_add_stream(th_transport_t *t, int pid,
                                  tv_streamtype_t type);
 
-
 #endif /* TRANSPORTS_H */
diff --git a/v4l.c b/v4l.c
index 0c2726191eb7ac3d37ea51b1f54cb6f681387a6b..d7bd26766b723555dfb8a07d3e91a46a53416ee7 100644 (file)
--- a/v4l.c
+++ b/v4l.c
@@ -200,7 +200,6 @@ v4l_stop_feed(th_transport_t *t)
   LIST_REMOVE(t, tht_adapter_link);
 
   t->tht_status = TRANSPORT_IDLE;
-  transport_flush_subscribers(t);
 
   if(LIST_FIRST(&tva->tva_transports) == NULL)
     v4l_stop(tva);