caps: fix race condition and memory leak in gst_static_caps_get
authorRené Stadler <rene.stadler@collabora.co.uk>
Mon, 17 Oct 2011 11:55:35 +0000 (13:55 +0200)
committerRené Stadler <rene.stadler@collabora.co.uk>
Mon, 17 Oct 2011 11:59:49 +0000 (13:59 +0200)
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.

gst/gstcaps.c

index 7d6acfe..e2a263e 100644 (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: