jitterbuffer: Don't leak duplicate items
authorEdward Hervey <bilboed@bilboed.com>
Thu, 1 Dec 2016 16:08:09 +0000 (17:08 +0100)
committerEdward Hervey <bilboed@bilboed.com>
Fri, 2 Dec 2016 08:01:57 +0000 (09:01 +0100)
When providing items with a seqnum, there is a (very small) probability
that an element with the same seqnum already exists. Don't forget
to free that item if it wasn't inserted.

And avoid returning undefined values when dealing with duplicate items

gst/rtpmanager/gstrtpjitterbuffer.c
gst/rtpmanager/rtpjitterbuffer.c

index a6e0b3a..2ca9fe7 100644 (file)
@@ -3757,7 +3757,9 @@ do_lost_timeout (GstRtpJitterBuffer * jitterbuffer, TimerData * timer,
             "retry", G_TYPE_UINT, num_rtx_retry, NULL));
   }
   item = alloc_item (event, ITEM_TYPE_LOST, -1, -1, seqnum, lost_packets, -1);
-  rtp_jitter_buffer_insert (priv->jbuf, item, &head, NULL);
+  if (!rtp_jitter_buffer_insert (priv->jbuf, item, &head, NULL))
+    /* Duplicate */
+    free_item (item);
 
   if (GST_CLOCK_TIME_IS_VALID (timer->rtx_last)) {
     /* Store info to update stats if the packet arrives too late */
index c31c8e6..03b7ebc 100644 (file)
@@ -1034,6 +1034,8 @@ append:
 duplicate:
   {
     GST_DEBUG ("duplicate packet %d found", (gint) seqnum);
+    if (G_LIKELY (head))
+      *head = FALSE;
     return FALSE;
   }
 }