From c800c8d4b5b327a45475875d70018efffe3040a0 Mon Sep 17 00:00:00 2001 From: Felix Riemann Date: Sun, 30 Aug 2009 11:22:49 -0400 Subject: [PATCH] Fix 593505: Memory leak in ChamplainLayer The list of children wasn't freed and the code was sub-optimal --- AUTHORS | 1 + champlain/champlain-layer.c | 14 ++++++++------ 2 files changed, 9 insertions(+), 6 deletions(-) diff --git a/AUTHORS b/AUTHORS index b5abf4c..328eabf 100644 --- a/AUTHORS +++ b/AUTHORS @@ -23,3 +23,4 @@ Tim Horton Frederic Peters Cosimo Cecchi Vincent Untz +Felix Riemann diff --git a/champlain/champlain-layer.c b/champlain/champlain-layer.c index 25cf61d..c6b6da2 100644 --- a/champlain/champlain-layer.c +++ b/champlain/champlain-layer.c @@ -118,24 +118,24 @@ reorder_marker (ClutterGroup *layer, ChamplainBaseMarker *marker) { GList* markers = clutter_container_get_children (CLUTTER_CONTAINER(layer)); - gint size, i; + GList* it; gdouble y, tmp_y, low_y; ChamplainBaseMarker *lowest = NULL; - size = g_list_length (markers); g_object_get (G_OBJECT (marker), "latitude", &y, NULL); y = 90 - y; low_y = G_MAXDOUBLE; - for (i = 0; i < size; i++) + for (it = markers; it != NULL; it = it->next) { - ChamplainBaseMarker *prev_marker = (ChamplainBaseMarker*) g_list_nth_data (markers, i); - g_object_get(G_OBJECT(prev_marker), "latitude", &tmp_y, NULL); - tmp_y = 90 - tmp_y; + ChamplainBaseMarker *prev_marker = (ChamplainBaseMarker*) it->data; if (prev_marker == (ChamplainBaseMarker*) marker) continue; + g_object_get(G_OBJECT(prev_marker), "latitude", &tmp_y, NULL); + tmp_y = 90 - tmp_y; + if (y < tmp_y && tmp_y < low_y) { lowest = prev_marker; @@ -146,6 +146,8 @@ reorder_marker (ClutterGroup *layer, if (lowest) clutter_container_lower_child (CLUTTER_CONTAINER(layer), CLUTTER_ACTOR (marker), CLUTTER_ACTOR (lowest)); + + g_list_free (markers); } static void -- 2.39.5