caps: fix race condition and memory leak in gst_static_caps_get

This was leaking the PtrArray from caps->priv, as set up by the other call to
gst_caps_init. Also, the thread safety issue presented in the comment above was
not taken care of anymore. We now zero the refcount again when publishing the
structure.

Fixes #661629.
This commit is contained in:
René Stadler 2011-10-17 13:55:35 +02:00
parent acd905d78a
commit 221836f452

View file

@ -374,10 +374,9 @@ gst_static_caps_get (GstStaticCaps * static_caps)
if (G_UNLIKELY (!gst_caps_from_string_inplace (&temp, string)))
g_critical ("Could not convert static caps \"%s\"", string);
gst_caps_init (caps, sizeof (GstCaps));
/* now copy stuff over to the real caps. */
GST_CAPS_FLAGS (caps) = GST_CAPS_FLAGS (&temp);
caps->priv = GST_CAPS_ARRAY (&temp);
GST_MINI_OBJECT_REFCOUNT (&temp) = 0;
memcpy (caps, &temp, sizeof (GstCaps));
gst_caps_ref (caps);
GST_CAT_TRACE (GST_CAT_CAPS, "created %p", static_caps);
done: