From: Pierre-Luc Beaudoin Date: Thu, 28 May 2009 04:37:49 +0000 (-0400) Subject: Implement proper dispose and finalize functions where needed X-Git-Url: https://err.no/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=cbdec7a35fd9bf9d3a729756dfc3f706db3c6f3a;p=libchamplain Implement proper dispose and finalize functions where needed --- diff --git a/champlain/champlain-cache.c b/champlain/champlain-cache.c index 64db6ff..60d2425 100644 --- a/champlain/champlain-cache.c +++ b/champlain/champlain-cache.c @@ -113,14 +113,24 @@ champlain_cache_dispose (GObject *object) ChamplainCachePrivate *priv = GET_PRIVATE (object); if (priv->stmt_select) - sqlite3_finalize (priv->stmt_select); + { + sqlite3_finalize (priv->stmt_select); + priv->stmt_select = NULL; + } if (priv->stmt_update) - sqlite3_finalize (priv->stmt_update); + { + sqlite3_finalize (priv->stmt_update); + priv->stmt_update = NULL; + } - error = sqlite3_close (priv->data); - if (error != SQLITE_OK) - DEBUG ("Sqlite returned error %d when closing cache.db", error); + if (priv->data != NULL) + { + error = sqlite3_close (priv->data); + if (error != SQLITE_OK) + DEBUG ("Sqlite returned error %d when closing cache.db", error); + priv->data = NULL; + } G_OBJECT_CLASS (champlain_cache_parent_class)->dispose (object); } diff --git a/champlain/champlain-layer.c b/champlain/champlain-layer.c index 3fe1d3d..0f802b6 100644 --- a/champlain/champlain-layer.c +++ b/champlain/champlain-layer.c @@ -85,20 +85,6 @@ champlain_layer_set_property (GObject *object, } } -static void -champlain_layer_dispose (GObject *object) -{ - //ChamplainLayerPrivate *priv = GET_PRIVATE (object); - - G_OBJECT_CLASS (champlain_layer_parent_class)->dispose (object); -} - -static void -champlain_layer_finalize (GObject *object) -{ - G_OBJECT_CLASS (champlain_layer_parent_class)->finalize (object); -} - static void champlain_layer_class_init (ChamplainLayerClass *klass) { @@ -108,8 +94,6 @@ champlain_layer_class_init (ChamplainLayerClass *klass) object_class->get_property = champlain_layer_get_property; object_class->set_property = champlain_layer_set_property; - object_class->dispose = champlain_layer_dispose; - object_class->finalize = champlain_layer_finalize; } static void diff --git a/champlain/champlain-tile.c b/champlain/champlain-tile.c index dd83614..876efdc 100644 --- a/champlain/champlain-tile.c +++ b/champlain/champlain-tile.c @@ -164,14 +164,17 @@ champlain_tile_dispose (GObject *object) { ChamplainTilePrivate *priv = GET_PRIVATE (object); - g_free (priv->uri); - g_free (priv->filename); if (priv->actor != NULL) { g_object_unref (G_OBJECT (priv->actor)); priv->actor = NULL; } - g_object_unref (priv->content_actor); + + if (priv->content_actor != NULL) + { + g_object_unref (G_OBJECT (priv->content_actor)); + priv->content_actor = NULL; + } G_OBJECT_CLASS (champlain_tile_parent_class)->dispose (object); } @@ -179,6 +182,11 @@ champlain_tile_dispose (GObject *object) static void champlain_tile_finalize (GObject *object) { + ChamplainTilePrivate *priv = GET_PRIVATE (object); + + g_free (priv->uri); + g_free (priv->filename); + G_OBJECT_CLASS (champlain_tile_parent_class)->finalize (object); } diff --git a/champlain/champlain-view.c b/champlain/champlain-view.c index 1de362c..c5ffaf5 100644 --- a/champlain/champlain-view.c +++ b/champlain/champlain-view.c @@ -172,7 +172,6 @@ static void champlain_view_get_property (GObject *object, guint prop_id, GValue *value, GParamSpec *pspec); static void champlain_view_set_property (GObject *object, guint prop_id, const GValue *value, GParamSpec *pspec); -static void champlain_view_finalize (GObject *object); static void champlain_view_dispose (GObject *object); static void champlain_view_class_init (ChamplainViewClass *champlainViewClass); static void champlain_view_init (ChamplainView *view); @@ -517,31 +516,65 @@ champlain_view_dispose (GObject *object) { ChamplainView *view = CHAMPLAIN_VIEW (object); ChamplainViewPrivate *priv = view->priv; - g_object_unref (priv->factory); - g_object_unref (priv->map_source); + + if (priv->factory) + { + g_object_unref (priv->factory); + priv->factory = NULL; + } + + if (priv->map_source) + { + g_object_unref (priv->map_source); + priv->map_source = NULL; + } + if (priv->license_actor) - g_object_unref (priv->license_actor); - g_object_unref (priv->finger_scroll); - g_object_unref (priv->viewport); - g_object_unref (priv->map_layer); - g_object_unref (priv->user_layers); - g_object_unref (priv->stage); + { + g_object_unref (priv->license_actor); + priv->license_actor = NULL; + } - map_free (priv->map); + if (priv->finger_scroll) + { + g_object_unref (priv->finger_scroll); + priv->finger_scroll = NULL; + } + + if (priv->viewport) + { + g_object_unref (priv->viewport); + priv->viewport = NULL; + } + + if (priv->map_layer) + { + g_object_unref (priv->map_layer); + priv->map_layer = NULL; + } + + if (priv->user_layers) + { + g_object_unref (priv->user_layers); + priv->user_layers = NULL; + } + + if (priv->stage) + { + g_object_unref (priv->stage); + priv->stage = NULL; + } + + if (priv->map) + { + map_free (priv->map); + priv->map = NULL; + } if (priv->goto_context) g_free (priv->goto_context); -} - -static void -champlain_view_finalize (GObject *object) -{ - /* - ChamplainView *view = CHAMPLAIN_VIEW (object); - ChamplainViewPrivate *priv = view->priv; - */ - G_OBJECT_CLASS (champlain_view_parent_class)->finalize (object); + G_OBJECT_CLASS (champlain_view_parent_class)->dispose (object); } static void @@ -550,7 +583,6 @@ champlain_view_class_init (ChamplainViewClass *champlainViewClass) g_type_class_add_private (champlainViewClass, sizeof (ChamplainViewPrivate)); GObjectClass *object_class = G_OBJECT_CLASS (champlainViewClass); - object_class->finalize = champlain_view_finalize; object_class->dispose = champlain_view_dispose; object_class->get_property = champlain_view_get_property; object_class->set_property = champlain_view_set_property; diff --git a/champlain/champlain-zoom-level.c b/champlain/champlain-zoom-level.c index b898fa1..9bb828a 100644 --- a/champlain/champlain-zoom-level.c +++ b/champlain/champlain-zoom-level.c @@ -113,15 +113,22 @@ champlain_zoom_level_dispose (GObject *object) ChamplainZoomLevel *level = CHAMPLAIN_ZOOM_LEVEL (object); ChamplainZoomLevelPrivate *priv = level->priv; - g_object_unref (priv->actor); + if (priv->actor != NULL) + { + g_object_unref (priv->actor); + priv->actor = NULL; + } - // Get rid of old tiles first - for (k = 0; k < champlain_zoom_level_tile_count (level); k++) + if (priv->tiles != NULL) { - ChamplainTile *tile = champlain_zoom_level_get_nth_tile (level, k); - champlain_zoom_level_remove_tile (level, tile); + for (k = 0; k < champlain_zoom_level_tile_count (level); k++) + { + ChamplainTile *tile = champlain_zoom_level_get_nth_tile (level, k); + champlain_zoom_level_remove_tile (level, tile); + } + g_ptr_array_free (priv->tiles, TRUE); + priv->tiles = NULL; } - g_ptr_array_free (priv->tiles, TRUE); G_OBJECT_CLASS (champlain_zoom_level_parent_class)->dispose (object); }