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
This commit is contained in:
Thijs Vermeir 2008-02-04 14:14:42 +00:00
parent 9db28f8537
commit bb3dfba3f5
3 changed files with 38 additions and 0 deletions

View file

@ -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):

View 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;

View 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;
}