[libchamplain] Add missing unrefs on destruction and fix possible memory leaks
- From: Jiří Techet <jiritechet src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [libchamplain] Add missing unrefs on destruction and fix possible memory leaks
- Date: Thu, 24 Mar 2011 23:13:32 +0000 (UTC)
commit ccb72582261099830916e6ef9ea90ae3f074d86c
Author: JiÅ?Ã Techet <techet gmail com>
Date: Mon Mar 21 23:23:14 2011 +0100
Add missing unrefs on destruction and fix possible memory leaks
champlain/champlain-license.c | 60 ++++++++++++++---------------------
champlain/champlain-marker-layer.c | 27 +++++++---------
champlain/champlain-path-layer.c | 13 +++++---
champlain/champlain-scale.c | 9 +++++-
4 files changed, 52 insertions(+), 57 deletions(-)
---
diff --git a/champlain/champlain-license.c b/champlain/champlain-license.c
index 7631dd7..195c36d 100644
--- a/champlain/champlain-license.c
+++ b/champlain/champlain-license.c
@@ -58,7 +58,6 @@ struct _ChamplainLicensePrivate
{
gchar *extra_text; /* Extra license text */
ClutterActor *license_actor;
- ClutterGroup *content_group;
ChamplainView *view;
};
@@ -117,7 +116,7 @@ paint (ClutterActor *self)
{
ChamplainLicensePrivate *priv = GET_PRIVATE (self);
- clutter_actor_paint (CLUTTER_ACTOR (priv->content_group));
+ clutter_actor_paint (CLUTTER_ACTOR (priv->license_actor));
}
@@ -129,7 +128,7 @@ pick (ClutterActor *self,
CLUTTER_ACTOR_CLASS (champlain_license_parent_class)->pick (self, color);
- clutter_actor_paint (CLUTTER_ACTOR (priv->content_group));
+ clutter_actor_paint (CLUTTER_ACTOR (priv->license_actor));
}
@@ -141,7 +140,7 @@ get_preferred_width (ClutterActor *self,
{
ChamplainLicensePrivate *priv = GET_PRIVATE (self);
- clutter_actor_get_preferred_width (CLUTTER_ACTOR (priv->content_group),
+ clutter_actor_get_preferred_width (CLUTTER_ACTOR (priv->license_actor),
for_height,
min_width_p,
natural_width_p);
@@ -156,7 +155,7 @@ get_preferred_height (ClutterActor *self,
{
ChamplainLicensePrivate *priv = GET_PRIVATE (self);
- clutter_actor_get_preferred_height (CLUTTER_ACTOR (priv->content_group),
+ clutter_actor_get_preferred_height (CLUTTER_ACTOR (priv->license_actor),
for_width,
min_height_p,
natural_height_p);
@@ -179,7 +178,7 @@ allocate (ClutterActor *self,
child_box.y1 = 0;
child_box.y2 = box->y2 - box->y1;
- clutter_actor_allocate (CLUTTER_ACTOR (priv->content_group), &child_box, flags);
+ clutter_actor_allocate (CLUTTER_ACTOR (priv->license_actor), &child_box, flags);
}
@@ -190,7 +189,7 @@ map (ClutterActor *self)
CLUTTER_ACTOR_CLASS (champlain_license_parent_class)->map (self);
- clutter_actor_map (CLUTTER_ACTOR (priv->content_group));
+ clutter_actor_map (CLUTTER_ACTOR (priv->license_actor));
}
@@ -201,7 +200,7 @@ unmap (ClutterActor *self)
CLUTTER_ACTOR_CLASS (champlain_license_parent_class)->unmap (self);
- clutter_actor_unmap (CLUTTER_ACTOR (priv->content_group));
+ clutter_actor_unmap (CLUTTER_ACTOR (priv->license_actor));
}
@@ -252,10 +251,16 @@ champlain_license_dispose (GObject *object)
{
ChamplainLicensePrivate *priv = CHAMPLAIN_LICENSE (object)->priv;
- if (priv->content_group)
+ if (priv->license_actor)
+ {
+ clutter_actor_unparent (CLUTTER_ACTOR (priv->license_actor));
+ priv->license_actor = NULL;
+ }
+
+ if (priv->view)
{
- clutter_actor_unparent (CLUTTER_ACTOR (priv->content_group));
- priv->content_group = NULL;
+ champlain_license_disconnect_view (CHAMPLAIN_LICENSE (object));
+ priv->view = NULL;
}
G_OBJECT_CLASS (champlain_license_parent_class)->dispose (object);
@@ -314,25 +319,6 @@ champlain_license_class_init (ChamplainLicenseClass *klass)
static void
-create_license (ChamplainLicense *license)
-{
- ChamplainLicensePrivate *priv = license->priv;
-
- if (priv->license_actor)
- {
- g_object_unref (priv->license_actor);
- clutter_container_remove_actor (CLUTTER_CONTAINER (license), priv->license_actor);
- }
-
- priv->license_actor = g_object_ref (clutter_text_new ());
- clutter_text_set_font_name (CLUTTER_TEXT (priv->license_actor), "sans 8");
- clutter_text_set_line_alignment (CLUTTER_TEXT (priv->license_actor), PANGO_ALIGN_RIGHT);
- clutter_actor_set_opacity (priv->license_actor, 128);
- clutter_container_add_actor (CLUTTER_CONTAINER (priv->content_group), priv->license_actor);
-}
-
-
-static void
champlain_license_init (ChamplainLicense *license)
{
ChamplainLicensePrivate *priv = GET_PRIVATE (license);
@@ -340,12 +326,13 @@ champlain_license_init (ChamplainLicense *license)
license->priv = priv;
priv->extra_text = NULL;
priv->view = NULL;
- priv->license_actor = NULL;
- priv->content_group = CLUTTER_GROUP (clutter_group_new ());
- clutter_actor_set_parent (CLUTTER_ACTOR (priv->content_group), CLUTTER_ACTOR (license));
- clutter_actor_queue_relayout (CLUTTER_ACTOR (license));
- create_license (license);
+ priv->license_actor = clutter_text_new ();
+ clutter_text_set_font_name (CLUTTER_TEXT (priv->license_actor), "sans 8");
+ clutter_text_set_line_alignment (CLUTTER_TEXT (priv->license_actor), PANGO_ALIGN_RIGHT);
+ clutter_actor_set_opacity (priv->license_actor, 128);
+ clutter_actor_set_parent (CLUTTER_ACTOR (priv->license_actor), CLUTTER_ACTOR (license));
+ clutter_actor_queue_relayout (CLUTTER_ACTOR (license));
}
@@ -381,7 +368,7 @@ champlain_license_connect_view (ChamplainLicense *license,
{
g_return_if_fail (CHAMPLAIN_IS_LICENSE (license));
- license->priv->view = view;
+ license->priv->view = g_object_ref (view);
g_signal_connect (view, "notify::map-source",
G_CALLBACK (redraw_license_cb), license);
@@ -405,6 +392,7 @@ champlain_license_disconnect_view (ChamplainLicense *license)
g_signal_handlers_disconnect_by_func (license->priv->view,
redraw_license_cb,
license);
+ g_object_unref (license->priv->view);
license->priv->view = NULL;
}
diff --git a/champlain/champlain-marker-layer.c b/champlain/champlain-marker-layer.c
index ebbf025..03b6729 100644
--- a/champlain/champlain-marker-layer.c
+++ b/champlain/champlain-marker-layer.c
@@ -214,6 +214,8 @@ champlain_marker_layer_dispose (GObject *object)
ChamplainMarkerLayer *self = CHAMPLAIN_MARKER_LAYER (object);
ChamplainMarkerLayerPrivate *priv = self->priv;
+ champlain_marker_layer_remove_all (CHAMPLAIN_MARKER_LAYER (object));
+
if (priv->view != NULL)
{
set_view (CHAMPLAIN_LAYER (self), NULL);
@@ -289,10 +291,8 @@ champlain_marker_layer_init (ChamplainMarkerLayer *self)
priv->mode = CHAMPLAIN_SELECTION_NONE;
priv->view = NULL;
- /* TODO destroy + ref() */
priv->content_group = CLUTTER_GROUP (clutter_group_new ());
clutter_actor_set_parent (CLUTTER_ACTOR (priv->content_group), CLUTTER_ACTOR (self));
-
clutter_actor_queue_relayout (CLUTTER_ACTOR (self));
}
@@ -370,9 +370,7 @@ marker_selected_cb (ChamplainMarker *marker,
ChamplainMarkerLayer *layer)
{
if (layer->priv->mode == CHAMPLAIN_SELECTION_SINGLE)
- {
- set_selected_all_but_one (layer, marker, FALSE);
- }
+ set_selected_all_but_one (layer, marker, FALSE);
}
@@ -491,6 +489,9 @@ champlain_marker_layer_remove_all (ChamplainMarkerLayer *layer)
g_signal_handlers_disconnect_by_func (marker,
G_CALLBACK (marker_position_notify), layer);
+
+ g_signal_handlers_disconnect_by_func (marker,
+ G_CALLBACK (marker_move_by_cb), layer);
}
champlain_group_remove_all (CHAMPLAIN_GROUP (priv->content_group));
@@ -578,6 +579,9 @@ champlain_marker_layer_remove_marker (ChamplainMarkerLayer *layer,
g_signal_handlers_disconnect_by_func (G_OBJECT (marker),
G_CALLBACK (marker_position_notify), layer);
+ g_signal_handlers_disconnect_by_func (marker,
+ G_CALLBACK (marker_move_by_cb), layer);
+
clutter_container_remove_actor (CLUTTER_CONTAINER (priv->content_group), CLUTTER_ACTOR (marker));
}
@@ -626,7 +630,6 @@ void
champlain_marker_layer_animate_out_all_markers (ChamplainMarkerLayer *layer)
{
ChamplainMarkerLayerPrivate *priv = GET_PRIVATE (layer);
-
GList *elem;
guint delay = 0;
GList *markers;
@@ -819,16 +822,12 @@ champlain_marker_layer_set_selection_mode (ChamplainMarkerLayer *layer,
{
g_return_if_fail (CHAMPLAIN_IS_MARKER_LAYER (layer));
- gboolean select;
-
if (layer->priv->mode == mode)
return;
layer->priv->mode = mode;
- select = mode != CHAMPLAIN_SELECTION_NONE &&
- mode != CHAMPLAIN_SELECTION_SINGLE;
-
- set_selected_all_but_one (layer, NULL, select);
+ if (mode != CHAMPLAIN_SELECTION_MULTIPLE)
+ set_selected_all_but_one (layer, NULL, FALSE);
g_object_notify (G_OBJECT (layer), "selection-mode");
}
@@ -847,9 +846,7 @@ champlain_marker_layer_set_selection_mode (ChamplainMarkerLayer *layer,
ChamplainSelectionMode
champlain_marker_layer_get_selection_mode (ChamplainMarkerLayer *layer)
{
- g_return_val_if_fail (
- CHAMPLAIN_IS_MARKER_LAYER (layer),
- CHAMPLAIN_SELECTION_SINGLE);
+ g_return_val_if_fail (CHAMPLAIN_IS_MARKER_LAYER (layer), CHAMPLAIN_SELECTION_SINGLE);
return layer->priv->mode;
}
diff --git a/champlain/champlain-path-layer.c b/champlain/champlain-path-layer.c
index ff81f19..a536958 100644
--- a/champlain/champlain-path-layer.c
+++ b/champlain/champlain-path-layer.c
@@ -292,10 +292,11 @@ champlain_path_layer_dispose (GObject *object)
ChamplainPathLayer *self = CHAMPLAIN_PATH_LAYER (object);
ChamplainPathLayerPrivate *priv = self->priv;
+ if (priv->nodes)
+ champlain_path_layer_remove_all (CHAMPLAIN_PATH_LAYER (object));
+
if (priv->view != NULL)
- {
- set_view (CHAMPLAIN_LAYER (self), NULL);
- }
+ set_view (CHAMPLAIN_LAYER (self), NULL);
if (priv->content_group)
{
@@ -315,7 +316,6 @@ champlain_path_layer_finalize (GObject *object)
clutter_color_free (priv->stroke_color);
clutter_color_free (priv->fill_color);
- g_list_free (priv->nodes);
G_OBJECT_CLASS (champlain_path_layer_parent_class)->finalize (object);
}
@@ -473,7 +473,6 @@ champlain_path_layer_init (ChamplainPathLayer *self)
priv->content_group = CLUTTER_GROUP (clutter_group_new ());
clutter_actor_set_parent (CLUTTER_ACTOR (priv->content_group), CLUTTER_ACTOR (self));
- /* TODO destroy + ref() */
priv->path_actor = clutter_cairo_texture_new (256, 256);
clutter_container_add_actor (CLUTTER_CONTAINER (priv->content_group), priv->path_actor);
@@ -773,6 +772,10 @@ set_view (ChamplainLayer *layer,
{
g_signal_handlers_disconnect_by_func (path_layer->priv->view,
G_CALLBACK (relocate_cb), path_layer);
+
+ g_signal_handlers_disconnect_by_func (path_layer->priv->view,
+ G_CALLBACK (redraw_path_cb), path_layer);
+
g_object_unref (path_layer->priv->view);
}
diff --git a/champlain/champlain-scale.c b/champlain/champlain-scale.c
index 8231855..d2573c6 100644
--- a/champlain/champlain-scale.c
+++ b/champlain/champlain-scale.c
@@ -230,6 +230,12 @@ champlain_scale_dispose (GObject *object)
priv->content_group = NULL;
}
+ if (priv->view)
+ {
+ champlain_scale_disconnect_view (CHAMPLAIN_SCALE (object));
+ priv->view = NULL;
+ }
+
G_OBJECT_CLASS (champlain_scale_parent_class)->dispose (object);
}
@@ -629,7 +635,7 @@ champlain_scale_connect_view (ChamplainScale *scale,
{
g_return_if_fail (CHAMPLAIN_IS_SCALE (scale));
- scale->priv->view = view;
+ scale->priv->view = g_object_ref (view);
g_signal_connect (view, "notify::latitude",
G_CALLBACK (redraw_scale_cb), scale);
schedule_redraw (scale);
@@ -652,5 +658,6 @@ champlain_scale_disconnect_view (ChamplainScale *scale)
g_signal_handlers_disconnect_by_func (scale->priv->view,
redraw_scale_cb,
scale);
+ g_object_unref (scale->priv->view);
scale->priv->view = NULL;
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]