From: Thijs Vermeir Date: Mon, 4 Feb 2008 14:14:42 +0000 (+0000) Subject: Be sure that we have a new copy of the caps and not reffed caps from a template X-Git-Tag: RELEASE-0_10_18~59 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=bb3dfba3f5a2232fdc1900b9cbf9c2e2718c5bd2;p=platform%2Fupstream%2Fgstreamer.git Be sure that we have a new copy of the caps and not reffed caps from a template 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 --- diff --git a/ChangeLog b/ChangeLog index 2e159cc..a546d93 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,10 @@ +2008-02-04 Thijs Vermeir + + * 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 * gst/gstbin.c: (gst_bin_get_type), (gst_bin_class_init): diff --git a/gst/gstpad.c b/gst/gstpad.c index eaac968..89f3220 100644 --- a/gst/gstpad.c +++ b/gst/gstpad.c @@ -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; diff --git a/tests/check/gst/gstpad.c b/tests/check/gst/gstpad.c index df02e11..f5e78a4 100644 --- a/tests/check/gst/gstpad.c +++ b/tests/check/gst/gstpad.c @@ -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; }