From 4724be167f19fe58cb38179e6f3b34b6797ff639 Mon Sep 17 00:00:00 2001 From: Neil Roberts Date: Wed, 6 Oct 2010 16:01:03 +0100 Subject: [PATCH] Plug a memory leak in clutter-table-layout Whenever the allocation is changed on a child of a ClutterTableLayout and animations are not in effect then it would store a copy of the allocation in the child meta data. However it was not freeing the old copy of the allocation so it would end up with a small leak. Instead of just changing it to free the old value this patch makes it store the allocation inline in the meta data struct because it seems that the size of an actor box is already quite small compared to the size of the meta data struct so it is probably not worth having a separate allocation for it. To detect the case when there has not yet been an allocation a separate boolean is used instead of storing NULL. http://bugzilla.clutter-project.org/show_bug.cgi?id=2358 --- clutter/clutter-table-layout.c | 39 ++++++++++++++-------------------- 1 file changed, 16 insertions(+), 23 deletions(-) diff --git a/clutter/clutter-table-layout.c b/clutter/clutter-table-layout.c index 97e683f56..d3840ab81 100644 --- a/clutter/clutter-table-layout.c +++ b/clutter/clutter-table-layout.c @@ -131,10 +131,11 @@ struct _ClutterTableChild { ClutterLayoutMeta parent_instance; - /* the last stable allocation before an animation; it is - * used as the initial ActorBox when interpolating + /* the last stable allocation before an animation; it is used as the + * initial ActorBox when interpolating. If has_last_allocation is + * FALSE then this value is not yet known */ - ClutterActorBox *last_allocation; + ClutterActorBox last_allocation; gint col; gint row; @@ -145,10 +146,11 @@ struct _ClutterTableChild ClutterTableAlignment x_align; ClutterTableAlignment y_align; - guint x_expand : 1; - guint y_expand : 1; - guint x_fill : 1; - guint y_fill : 1; + guint x_expand : 1; + guint y_expand : 1; + guint x_fill : 1; + guint y_fill : 1; + guint has_last_allocation : 1; }; enum @@ -570,16 +572,6 @@ clutter_table_child_get_property (GObject *gobject, } } -static void -clutter_table_child_finalize (GObject *gobject) -{ - ClutterTableChild *self = CLUTTER_TABLE_CHILD (gobject); - - clutter_actor_box_free (self->last_allocation); - - G_OBJECT_CLASS (clutter_table_child_parent_class)->finalize (gobject); -} - static void clutter_table_child_class_init (ClutterTableChildClass *klass) { @@ -588,7 +580,6 @@ clutter_table_child_class_init (ClutterTableChildClass *klass) gobject_class->set_property = clutter_table_child_set_property; gobject_class->get_property = clutter_table_child_get_property; - gobject_class->finalize = clutter_table_child_finalize; pspec = g_param_spec_int ("column", P_("Column Number"), @@ -696,7 +687,7 @@ clutter_table_child_init (ClutterTableChild *self) self->x_fill = TRUE; self->y_fill = TRUE; - self->last_allocation = NULL; + self->has_last_allocation = FALSE; } static GType @@ -1532,18 +1523,19 @@ clutter_table_layout_allocate (ClutterLayoutManager *layout, p = clutter_layout_manager_get_animation_progress (layout); - start = meta->last_allocation; - if (start == NULL) + if (!meta->has_last_allocation) { /* if there is no allocation available then the child has just * been added to the container; we put it in the final state * and store its allocation for later */ - meta->last_allocation = clutter_actor_box_copy (&childbox); + meta->last_allocation = childbox; + meta->has_last_allocation = TRUE; goto do_allocate; } + start = &meta->last_allocation; end = childbox; /* interpolate between the initial and final values */ @@ -1564,7 +1556,8 @@ clutter_table_layout_allocate (ClutterLayoutManager *layout, else { /* store the allocation for later animations */ - meta->last_allocation = clutter_actor_box_copy (&childbox); + meta->last_allocation = childbox; + meta->has_last_allocation = TRUE; } do_allocate: