[libgda] GdaDataProxy: avoid memory leak and wrong mutex usage



commit f2ac15b5ffc7c7ffeb8c85ebc434b76b0dc6a16d
Author: Vivien Malerba <malerba gnome-db org>
Date:   Sat May 5 15:00:13 2012 +0200

    GdaDataProxy: avoid memory leak and wrong mutex usage

 libgda/gda-data-proxy.c |   18 ++++++++++++------
 1 files changed, 12 insertions(+), 6 deletions(-)
---
diff --git a/libgda/gda-data-proxy.c b/libgda/gda-data-proxy.c
index 5787e66..8e20d43 100644
--- a/libgda/gda-data-proxy.c
+++ b/libgda/gda-data-proxy.c
@@ -726,11 +726,10 @@ gda_data_proxy_data_model_init (GdaDataModelIface *iface)
 }
 
 static void
-gda_data_proxy_init (GdaDataProxy *proxy)
+do_init (GdaDataProxy *proxy)
 {
-	proxy->priv = g_new0 (GdaDataProxyPrivate, 1);
-
-	proxy->priv->mutex = gda_mutex_new ();
+	if (!proxy->priv->mutex)
+		proxy->priv->mutex = gda_mutex_new ();
 
 	proxy->priv->modify_rows = g_hash_table_new_full (g_int_hash, g_int_equal, g_free, NULL);
 	proxy->priv->notify_changes = TRUE;
@@ -749,6 +748,13 @@ gda_data_proxy_init (GdaDataProxy *proxy)
 	proxy->priv->catched_inserted_row = -1;
 }
 
+static void
+gda_data_proxy_init (GdaDataProxy *proxy)
+{
+	proxy->priv = g_new0 (GdaDataProxyPrivate, 1);
+	do_init (proxy);
+}
+
 static DisplayChunk *compute_display_chunk (GdaDataProxy *proxy);
 static void adjust_displayed_chunk (GdaDataProxy *proxy);
 static gboolean chunk_sync_idle (GdaDataProxy *proxy);
@@ -938,7 +944,7 @@ gda_data_proxy_set_property (GObject *object,
 		case PROP_MODEL:
 			if (proxy->priv->model) {
 				clean_proxy (proxy);
-				gda_data_proxy_init (proxy);
+				do_init (proxy);
 			}
 
 			model = (GdaDataModel*) g_value_get_object (value);
@@ -1226,7 +1232,7 @@ proxied_model_reset_cb (GdaDataModel *model, GdaDataProxy *proxy)
 
 	g_object_ref (G_OBJECT (model));
 	clean_proxy (proxy);
-	gda_data_proxy_init (proxy);
+	do_init (proxy);
 	g_object_set (G_OBJECT (proxy), "model", model, "prepend-null-entry", add_null_entry, NULL);
 	g_object_unref (G_OBJECT (model));
 



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]