From 7485b66d0605a65e57493d18a0a1357318f42251 Mon Sep 17 00:00:00 2001 From: Stefan Sauer Date: Fri, 13 Apr 2012 08:10:19 +0200 Subject: [PATCH] controlbinding: only take a weak ref on the object Fixes the leaks in the tests. Added a TODO comment to eventually rework this some more (while we can). --- gst/gstcontrolbinding.c | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/gst/gstcontrolbinding.c b/gst/gstcontrolbinding.c index 74d078e8ae..b9b7bd89ab 100644 --- a/gst/gstcontrolbinding.c +++ b/gst/gstcontrolbinding.c @@ -25,6 +25,13 @@ * * A value mapping object that attaches control sources to gobject properties. */ +/* FIXME(ensonic): should we make gst_object_add_control_binding() internal + * - we create the control_binding for a certain object anyway + * - we could call gst_object_add_control_binding() at the end of + * gst_control_binding_constructor() + * - the weak-ref on object is not nice, as is the same as gst_object_parent() + * once the object is added to the parent + */ #include "gst_private.h" @@ -130,8 +137,10 @@ gst_control_binding_dispose (GObject * object) { GstControlBinding *self = GST_CONTROL_BINDING (object); - if (self->object) - gst_object_replace (&self->object, NULL); + /* we did not took a reference */ + g_object_remove_weak_pointer ((GObject *) self->object, + (gpointer *) & self->object); + self->object = NULL; ((GObjectClass *) gst_control_binding_parent_class)->dispose (object); } @@ -154,7 +163,10 @@ gst_control_binding_set_property (GObject * object, guint prop_id, switch (prop_id) { case PROP_OBJECT: - self->object = g_value_dup_object (value); + /* do not ref to avoid a ref cycle */ + self->object = g_value_get_object (value); + g_object_add_weak_pointer ((GObject *) self->object, + (gpointer *) & self->object); break; case PROP_NAME: self->name = g_value_dup_string (value);