audiodecoder: Plug caps leaks
authorEdward Hervey <bilboed@bilboed.com>
Fri, 25 Apr 2014 09:30:37 +0000 (11:30 +0200)
committerEdward Hervey <bilboed@bilboed.com>
Fri, 25 Apr 2014 09:30:37 +0000 (11:30 +0200)
We were returning in various places without unreffing the caps, and
we were also leaking (overwriting) the caps we got from _get_current_caps()

Spotted by Haakon Sporsheim in #gstreamer

gst-libs/gst/audio/gstaudiodecoder.c

index be8a3e1..7f086fe 100644 (file)
@@ -1833,11 +1833,13 @@ gst_audio_decoder_negotiate_default_caps (GstAudioDecoder * dec)
 
   caps = gst_pad_get_current_caps (dec->srcpad);
   if (caps && !gst_audio_info_from_caps (&dec->priv->ctx.info, caps))
-    return FALSE;
+    goto caps_error;
+  if (caps)
+    gst_caps_unref (caps);
 
   caps = gst_pad_get_allowed_caps (dec->srcpad);
   if (!caps || gst_caps_is_empty (caps) || gst_caps_is_any (caps))
-    return FALSE;
+    goto caps_error;
 
   /* before fixating, try to use whatever upstream provided */
   caps_size = gst_caps_get_size (caps);
@@ -1896,7 +1898,7 @@ gst_audio_decoder_negotiate_default_caps (GstAudioDecoder * dec)
   }
 
   if (!caps || !gst_audio_info_from_caps (&dec->priv->ctx.info, caps))
-    return FALSE;
+    goto caps_error;
 
   GST_INFO_OBJECT (dec,
       "Chose default caps %" GST_PTR_FORMAT " for initial gap", caps);
@@ -1909,6 +1911,13 @@ gst_audio_decoder_negotiate_default_caps (GstAudioDecoder * dec)
   }
 
   return TRUE;
+
+caps_error:
+  {
+    if (caps)
+      gst_caps_unref (caps);
+    return FALSE;
+  }
 }
 
 static gboolean