]> git.ipfire.org Git - thirdparty/tvheadend.git/commitdiff
timeshift: fix the wrong sorting queue updates (thus crashes)
authorJaroslav Kysela <perex@perex.cz>
Tue, 5 Jan 2016 12:47:29 +0000 (13:47 +0100)
committerJaroslav Kysela <perex@perex.cz>
Tue, 5 Jan 2016 12:47:29 +0000 (13:47 +0100)
src/timeshift.c

index 5e369bba93c39a006c3549c893fb17aef0e60d9b..ba9acb3e3e7af1b06b5cca3ca7bc303d944e200b 100644 (file)
@@ -248,35 +248,38 @@ static void
 timeshift_packet_flush ( timeshift_t *ts, int64_t time )
 {
   streaming_message_t *lowest, *sm;
-  struct streaming_message_queue *sq;
+  struct streaming_message_queue *sq, *sq_lowest;
   int i;
 
   while (1) {
     lowest = NULL;
+    sq_lowest = NULL;
     for (i = 0; i < ts->backlog_max; i++) {
       sq = &ts->backlog[i];
       sm = TAILQ_FIRST(sq);
       if (sm && sm->sm_time + MAX_TIME_DELTA < time)
-        if (lowest == NULL || lowest->sm_time > sm->sm_time)
+        if (lowest == NULL || lowest->sm_time > sm->sm_time) {
           lowest = sm;
+          sq_lowest = sq;
+        }
     }
     if (!lowest)
       break;
-    TAILQ_REMOVE(sq, lowest, sm_link);
+    TAILQ_REMOVE(sq_lowest, lowest, sm_link);
     ts->last_wr_time = lowest->sm_time;
     timeshift_packet_log("wr ", ts, lowest);
     streaming_target_deliver2(&ts->wr_queue.sq_st, lowest);
   }
 }
 
-static void
+static int
 timeshift_packet( timeshift_t *ts, streaming_message_t *sm )
 {
   th_pkt_t *pkt = sm->sm_data;
   int64_t time;
 
   if (pkt->pkt_componentindex >= TIMESHIFT_BACKLOG_MAX)
-    return;
+    return -1;
 
   time = ts_rescale(pkt->pkt_pts, 1000000);
   if (time > ts->last_time) {
@@ -294,6 +297,7 @@ timeshift_packet( timeshift_t *ts, streaming_message_t *sm )
       ts->backlog_max = pkt->pkt_componentindex + 1;
     TAILQ_INSERT_TAIL(&ts->backlog[pkt->pkt_componentindex], sm, sm_link);
   }
+  return 0;
 }
 
 /*
@@ -339,10 +343,8 @@ static void timeshift_input
     /* Send to the writer thread */
     if (ts->packet_mode) {
       sm->sm_time = ts->last_wr_time;
-      if (type == SMT_PACKET) {
-        timeshift_packet(ts, sm);
+      if ((type == SMT_PACKET) && !timeshift_packet(ts, sm))
         goto _exit;
-      }
     } else {
       if (ts->ref_time == 0) {
         ts->ref_time = getmonoclock();