queue[2]: Make src query MT-safe
authorHavard Graff <havard.graff@tandberg.com>
Sat, 19 Mar 2011 23:56:08 +0000 (00:56 +0100)
committerSebastian Dröge <sebastian.droege@collabora.co.uk>
Fri, 8 Apr 2011 12:58:51 +0000 (14:58 +0200)
It is possible that the element might be going down while the event arrives

plugins/elements/gstqueue.c
plugins/elements/gstqueue2.c

index e9e79f4..2594f04 100644 (file)
@@ -1304,17 +1304,24 @@ gst_queue_handle_src_event (GstPad * pad, GstEvent * event)
 static gboolean
 gst_queue_handle_src_query (GstPad * pad, GstQuery * query)
 {
-  GstQueue *queue = GST_QUEUE (GST_PAD_PARENT (pad));
+  GstQueue *queue = GST_QUEUE (gst_pad_get_parent (pad));
   GstPad *peer;
   gboolean res;
 
-  if (!(peer = gst_pad_get_peer (queue->sinkpad)))
+  if (G_UNLIKELY (queue == NULL))
     return FALSE;
 
+  if (!(peer = gst_pad_get_peer (queue->sinkpad))) {
+    gst_object_unref (queue);
+    return FALSE;
+  }
+
   res = gst_pad_query (peer, query);
   gst_object_unref (peer);
-  if (!res)
+  if (!res) {
+    gst_object_unref (queue);
     return FALSE;
+  }
 
   switch (GST_QUERY_TYPE (query)) {
     case GST_QUERY_POSITION:
@@ -1370,6 +1377,7 @@ gst_queue_handle_src_query (GstPad * pad, GstQuery * query)
       break;
   }
 
+  gst_object_unref (queue);
   return TRUE;
 }
 
index 0a2b28c..431c131 100644 (file)
@@ -2441,7 +2441,9 @@ gst_queue2_handle_src_query (GstPad * pad, GstQuery * query)
 {
   GstQueue2 *queue;
 
-  queue = GST_QUEUE2 (GST_PAD_PARENT (pad));
+  queue = GST_QUEUE2 (gst_pad_get_parent (pad));
+  if (G_UNLIKELY (queue == NULL))
+    return FALSE;
 
   switch (GST_QUERY_TYPE (query)) {
     case GST_QUERY_POSITION:
@@ -2612,12 +2614,14 @@ gst_queue2_handle_src_query (GstPad * pad, GstQuery * query)
       break;
   }
 
+  gst_object_unref (queue);
   return TRUE;
 
   /* ERRORS */
 peer_failed:
   {
     GST_DEBUG_OBJECT (queue, "failed peer query");
+    gst_object_unref (queue);
     return FALSE;
   }
 }