gstutils: Fix a pad leak
authorEdward Hervey <edward@centricular.com>
Mon, 28 Nov 2016 12:48:16 +0000 (13:48 +0100)
committerEdward Hervey <bilboed@bilboed.com>
Mon, 28 Nov 2016 17:28:33 +0000 (18:28 +0100)
When requesting a pad from a template and it's already linked, this
means it was a static pad. Since we only want to return an *available*
pad, we must return NULL ... but we must also remove the reference
we got from getting that static pad.

The "No need to unref" message (which wasn't true for quite some time)
dates back from the very very very first commit introducing the 0.10
features.

gst/gstutils.c

index e1265a09ff7389c37e12dd627d41c6747c3f3bad..e64b41fba00e6c1898f9461a44262af74d5ece2b 100644 (file)
@@ -909,10 +909,11 @@ gst_element_request_compatible_pad (GstElement * element,
   templ_new = gst_element_get_compatible_pad_template (element, templ);
   if (templ_new)
     pad = gst_element_get_pad_from_template (element, templ_new);
-
-  /* This can happen for non-request pads. No need to unref. */
-  if (pad && GST_PAD_PEER (pad))
+  /* This can happen for non-request pads. */
+  if (pad && GST_PAD_PEER (pad)) {
+    gst_object_unref (pad);
     pad = NULL;
+  }
 
   return pad;
 }