From: =?UTF-8?q?Tim-Philipp=20M=C3=BCller?= <tim@centricular.net>
Date: Sat, 27 Apr 2013 00:05:45 +0100
Subject: typefind: fix caps leak when used in connection with uridecodebin and
 playbin

Don't leak forced sink caps.

diff --git a/plugins/elements/gsttypefindelement.c b/plugins/elements/gsttypefindelement.c
--- a/plugins/elements/gsttypefindelement.c
+++ b/plugins/elements/gsttypefindelement.c
@@ -1195,6 +1195,7 @@ gst_type_find_element_activate_sink (GstPad * pad, GstObject * parent)
     GST_DEBUG ("Emiting found caps %" GST_PTR_FORMAT, found_caps);
     g_signal_emit (typefind, gst_type_find_element_signals[HAVE_TYPE],
         0, probability, found_caps);
+    gst_caps_unref (found_caps);
     typefind->mode = MODE_NORMAL;
     /* the signal above could have made a downstream element activate
      * the pad in pull mode, we check if the pad is already active now and if
diff --git a/tests/check/pipelines/simple-launch-lines.c b/tests/check/pipelines/simple-launch-lines.c
--- a/tests/check/pipelines/simple-launch-lines.c
+++ b/tests/check/pipelines/simple-launch-lines.c
@@ -310,6 +310,20 @@ GST_START_TEST (test_stop_from_app)
 
 GST_END_TEST;
 
+GST_START_TEST (test_typefind_force_sink_caps)
+{
+  const gchar *s;
+
+  s = "fakesrc can-activate-push=true num-buffers=5 ! "
+      "typefind force-caps=foo/x-bar ! fakesink can-activate-push=true";
+  ASSERT_CRITICAL (run_pipeline (setup_pipeline (s), s,
+          GST_MESSAGE_NEW_CLOCK | GST_MESSAGE_STATE_CHANGED |
+          GST_MESSAGE_STREAM_STATUS | GST_MESSAGE_ASYNC_DONE |
+          GST_MESSAGE_STREAM_START, GST_MESSAGE_UNKNOWN));
+}
+
+GST_END_TEST;
+
 static Suite *
 simple_launch_lines_suite (void)
 {
@@ -324,6 +338,8 @@ simple_launch_lines_suite (void)
   tcase_add_test (tc_chain, test_state_change_returns);
   /* tcase_add_test (tc_chain, test_tee); FIXME */
   tcase_add_test (tc_chain, test_stop_from_app);
+  tcase_add_test (tc_chain, test_typefind_force_sink_caps);
+
   return s;
 }
 
