]> err.no Git - libchamplain/commitdiff
Implement proper dispose and finalize functions where needed
authorPierre-Luc Beaudoin <pierre-luc@pierlux.com>
Thu, 28 May 2009 04:37:49 +0000 (00:37 -0400)
committerPierre-Luc Beaudoin <pierre-luc@pierlux.com>
Thu, 28 May 2009 04:37:49 +0000 (00:37 -0400)
champlain/champlain-cache.c
champlain/champlain-layer.c
champlain/champlain-tile.c
champlain/champlain-view.c
champlain/champlain-zoom-level.c

index 64db6ff4d27d35c222ba1ad185613d90c7a9ac0c..60d24252d04fa0e26e379f459dffa2b012e97cc7 100644 (file)
@@ -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);
 }
index 3fe1d3d05c43e3772df83eee26bcdf6d05094c60..0f802b65de63b6a9b89a5e2cfb4860240ee1c75b 100644 (file)
@@ -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
index dd836141535830ab31345cc64f6349bf742aa1fb..876efdc8435a886b56cc6213f527b18dc8bf14c7 100644 (file)
@@ -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);
 }
 
index 1de362c822bf3ffa2f93ac1a2c2406c8da12b8fe..c5ffaf5edd3f2a17ec045fcf6cc19405085c0f67 100644 (file)
@@ -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;
index b898fa1ac8417f87c60309a7149dd0609384ac49..9bb828a4d9434fdcb3b1c6c7c8a43c1851f61057 100644 (file)
@@ -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);
 }