Be sure that we have a new copy of the caps and not reffed caps from a template
authorThijs Vermeir <thijsvermeir@gmail.com>
Mon, 4 Feb 2008 14:14:42 +0000 (14:14 +0000)
committerThijs Vermeir <thijsvermeir@gmail.com>
Mon, 4 Feb 2008 14:14:42 +0000 (14:14 +0000)
Original commit message from CVS:
* gst/gstpad.c:
* tests/check/gst/gstpad.c:
Be sure that we have a new copy of the caps and not
reffed caps from a template

ChangeLog
gst/gstpad.c
tests/check/gst/gstpad.c

index 2e159cc..a546d93 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,10 @@
+2008-02-04  Thijs Vermeir  <thijsvermeir@gmail.com>
+
+       * gst/gstpad.c:
+       * tests/check/gst/gstpad.c:
+       Be sure that we have a new copy of the caps and not
+       reffed caps from a template
+
 2008-02-03  Sebastian Dröge  <slomo@circular-chaos.org>
 
        * gst/gstbin.c: (gst_bin_get_type), (gst_bin_class_init):
index eaac968..89f3220 100644 (file)
@@ -2059,6 +2059,11 @@ gst_pad_get_caps (GstPad * pad)
   GST_CAT_DEBUG_OBJECT (GST_CAT_CAPS, pad, "get pad caps");
 
   result = gst_pad_get_caps_unlocked (pad);
+
+  /* be sure that we have a copy */
+  if (result)
+    result = gst_caps_make_writable (result);
+
   GST_OBJECT_UNLOCK (pad);
 
   return result;
index df02e11..f5e78a4 100644 (file)
@@ -578,6 +578,31 @@ GST_START_TEST (test_sink_unref_unlink)
 
 GST_END_TEST;
 
+/* gst_pad_get_caps should return a copy of the caps */
+GST_START_TEST (test_get_caps_must_be_copy)
+{
+  GstPad *pad;
+  GstCaps *caps;
+  GstPadTemplate *templ;
+
+  caps = gst_caps_new_any ();
+  templ =
+      gst_pad_template_new ("test_templ", GST_PAD_SRC, GST_PAD_ALWAYS, caps);
+  pad = gst_pad_new_from_template (templ, NULL);
+  fail_unless (GST_PAD_CAPS (pad) == NULL, "caps present on pad");
+  caps = gst_pad_get_caps (pad);
+
+  /* we must own the caps */
+  ASSERT_OBJECT_REFCOUNT (caps, "caps", 1);
+
+  /* cleanup */
+  gst_caps_unref (caps);
+  gst_object_unref (pad);
+  gst_object_unref (templ);
+}
+
+GST_END_TEST;
+
 Suite *
 gst_pad_suite (void)
 {
@@ -599,6 +624,7 @@ gst_pad_suite (void)
   tcase_add_test (tc_chain, test_push_negotiation);
   tcase_add_test (tc_chain, test_src_unref_unlink);
   tcase_add_test (tc_chain, test_sink_unref_unlink);
+  tcase_add_test (tc_chain, test_get_caps_must_be_copy);
 
   return s;
 }