multiqueue: two small fixes for when an existing pad is requested
authorTim-Philipp Müller <tim@centricular.com>
Wed, 20 Jan 2016 09:57:00 +0000 (09:57 +0000)
committerTim-Philipp Müller <tim@centricular.com>
Wed, 20 Jan 2016 10:06:14 +0000 (10:06 +0000)
Unlock when returning NULL from gst_single_queue_new(), and don't
crash with debug logging enabled if NULL is returned.

Spotted by Steven Hoving.

plugins/elements/gstmultiqueue.c

index bd0b06c..9437edc 100644 (file)
@@ -762,6 +762,7 @@ gst_multi_queue_request_new_pad (GstElement * element, GstPadTemplate * temp,
 {
   GstMultiQueue *mqueue = GST_MULTI_QUEUE (element);
   GstSingleQueue *squeue;
+  GstPad *new_pad;
   guint temp_id = -1;
 
   if (name) {
@@ -772,10 +773,11 @@ gst_multi_queue_request_new_pad (GstElement * element, GstPadTemplate * temp,
   /* Create a new single queue, add the sink and source pad and return the sink pad */
   squeue = gst_single_queue_new (mqueue, temp_id);
 
-  GST_DEBUG_OBJECT (mqueue, "Returning pad %s:%s",
-      GST_DEBUG_PAD_NAME (squeue->sinkpad));
+  new_pad = squeue ? squeue->sinkpad : NULL;
 
-  return squeue ? squeue->sinkpad : NULL;
+  GST_DEBUG_OBJECT (mqueue, "Returning pad %" GST_PTR_FORMAT, new_pad);
+
+  return new_pad;
 }
 
 static void
@@ -2627,10 +2629,12 @@ gst_single_queue_new (GstMultiQueue * mqueue, guint id)
     if (sq2->id == temp_id) {
       /* If this ID was requested by the caller return NULL,
        * otherwise just get us the next one */
-      if (id == -1)
+      if (id == -1) {
         temp_id = sq2->id + 1;
-      else
+      } else {
+        GST_MULTI_QUEUE_MUTEX_UNLOCK (mqueue);
         return NULL;
+      }
     } else if (sq2->id > temp_id) {
       break;
     }