[anjuta] symbol-db, ls-cpp-java, document-manager: fixed query leaks



commit 0039db125d5cb038fead1257e6866c4921b8127d
Author: Massimo Corà <mcora src gnome org>
Date:   Fri Jan 7 00:06:14 2011 +0100

    symbol-db, ls-cpp-java, document-manager: fixed query leaks
    
    There were many IAnjutaSymbolQuery objects leaked in bookmarks, cpp-assist, engine-parser.

 plugins/document-manager/anjuta-bookmarks.c        |   50 +++++++++++++-------
 .../language-support-cpp-java/cpp-java-assist.c    |   34 +++++++++++++
 .../cxxparser/engine-parser-priv.h                 |    1 +
 .../cxxparser/engine-parser.cpp                    |   26 ++++++++++
 .../cxxparser/engine-parser.h                      |    2 +
 plugins/symbol-db/plugin.c                         |    7 +++
 plugins/symbol-db/symbol-db-query.c                |    7 ++-
 7 files changed, 107 insertions(+), 20 deletions(-)
---
diff --git a/plugins/document-manager/anjuta-bookmarks.c b/plugins/document-manager/anjuta-bookmarks.c
index 63d58aa..88f5201 100644
--- a/plugins/document-manager/anjuta-bookmarks.c
+++ b/plugins/document-manager/anjuta-bookmarks.c
@@ -54,8 +54,8 @@ struct _AnjutaBookmarksPrivate
 	GtkWidget* button_remove;
 	GtkWidget* grip;
 
+	IAnjutaSymbolQuery* query_scope;
 	GtkWidget* menu;
-	IAnjutaSymbolQuery *query_scope;
 	DocmanPlugin* docman;
 };
 
@@ -379,8 +379,7 @@ anjuta_bookmarks_finalize (GObject *object)
 {
 	AnjutaBookmarks* bookmarks = ANJUTA_BOOKMARKS (object);
 	AnjutaBookmarksPrivate* priv = BOOKMARKS_GET_PRIVATE(bookmarks);
-
-	g_object_unref (priv->query_scope);
+	
 	gtk_widget_destroy (priv->menu);
 	
 	anjuta_shell_remove_widget (ANJUTA_PLUGIN(priv->docman)->shell,
@@ -409,18 +408,6 @@ anjuta_bookmarks_new (DocmanPlugin* docman)
 	AnjutaBookmarksPrivate* priv = BOOKMARKS_GET_PRIVATE(bookmarks);
 	priv->docman = docman;
 
-	IAnjutaSymbolManager* sym_manager;
-	static IAnjutaSymbolField fields[] = {IANJUTA_SYMBOL_FIELD_NAME};
-	
-	sym_manager = anjuta_shell_get_interface (ANJUTA_PLUGIN(priv->docman)->shell,
-											  IAnjutaSymbolManager, NULL);
-	priv->query_scope =
-		ianjuta_symbol_manager_create_query (sym_manager,
-											 IANJUTA_SYMBOL_QUERY_SEARCH_SCOPE,
-											  IANJUTA_SYMBOL_QUERY_DB_PROJECT,
-											  NULL);
-	ianjuta_symbol_query_set_fields (priv->query_scope, 1, fields, NULL);
-	
 	anjuta_shell_add_widget_custom (ANJUTA_PLUGIN(docman)->shell,
 	                                priv->window,
 	                                "bookmarks",
@@ -437,12 +424,33 @@ anjuta_bookmarks_new (DocmanPlugin* docman)
 	return bookmarks;
 }
 
+static IAnjutaSymbolQuery*
+anjuta_bookmarks_create_query (AnjutaBookmarks* bookmarks)
+{
+	AnjutaBookmarksPrivate* priv = BOOKMARKS_GET_PRIVATE(bookmarks);
+	IAnjutaSymbolManager* sym_manager;
+	static IAnjutaSymbolField fields[] = {IANJUTA_SYMBOL_FIELD_NAME};
+	
+	sym_manager = anjuta_shell_get_interface (ANJUTA_PLUGIN(priv->docman)->shell,
+											  IAnjutaSymbolManager, NULL);
+	
+	IAnjutaSymbolQuery * query_scope =
+		ianjuta_symbol_manager_create_query (sym_manager,
+											 IANJUTA_SYMBOL_QUERY_SEARCH_SCOPE,
+											  IANJUTA_SYMBOL_QUERY_DB_PROJECT,
+											  NULL);
+	ianjuta_symbol_query_set_fields (query_scope, 1, fields, NULL);
+	
+	return query_scope;
+}
+
 static gchar*
 anjuta_bookmarks_get_text_from_file (AnjutaBookmarks* bookmarks, GFile* file, gint line)
 {
-	gchar* text;
 	AnjutaBookmarksPrivate* priv = BOOKMARKS_GET_PRIVATE(bookmarks);
-
+	gchar* text;
+	
+	
 	if (priv->query_scope != NULL)
 	{
 		gchar* path = g_file_get_path (file);
@@ -458,7 +466,7 @@ anjuta_bookmarks_get_text_from_file (AnjutaBookmarks* bookmarks, GFile* file, gi
 			                                         NULL);
 			text = g_strdup_printf ("%s:%d", symbol_name,
 			                        line);
-			g_object_unref (iter);
+			g_object_unref (iter);			
 			return text;
 		}
 	}
@@ -740,6 +748,9 @@ anjuta_bookmarks_session_save (AnjutaBookmarks* bookmarks, AnjutaSession* sessio
 	
 	/* Clear the model */
 	gtk_list_store_clear (GTK_LIST_STORE (priv->model));
+
+	if (priv->query_scope)
+		g_object_unref (priv->query_scope);
 }
 
 void 
@@ -822,6 +833,7 @@ read_bookmarks (AnjutaBookmarks* bookmarks, xmlNodePtr marks)
 void
 anjuta_bookmarks_session_load (AnjutaBookmarks* bookmarks, AnjutaSession* session)
 {
+	AnjutaBookmarksPrivate* priv = BOOKMARKS_GET_PRIVATE(bookmarks);	
 	gchar* xml_string = anjuta_session_get_string (session,
 												   "Document Manager",
 												   "bookmarks");
@@ -845,6 +857,8 @@ anjuta_bookmarks_session_load (AnjutaBookmarks* bookmarks, AnjutaSession* sessio
 		read_bookmarks (bookmarks, cur->children);
 	
 	xmlFreeDoc (doc);
+
+	priv->query_scope = anjuta_bookmarks_create_query (bookmarks);
 }
 
 static gint
diff --git a/plugins/language-support-cpp-java/cpp-java-assist.c b/plugins/language-support-cpp-java/cpp-java-assist.c
index 9dc50ef..967402f 100644
--- a/plugins/language-support-cpp-java/cpp-java-assist.c
+++ b/plugins/language-support-cpp-java/cpp-java-assist.c
@@ -1345,9 +1345,43 @@ static void
 cpp_java_assist_finalize (GObject *object)
 {
 	CppJavaAssist *assist = CPP_JAVA_ASSIST (object);
+	CppJavaAssistPriv* priv = assist->priv;
+	
 	cpp_java_assist_uninstall (assist);
 	cpp_java_assist_clear_completion_cache (assist);
 	cpp_java_assist_clear_calltip_context (assist);
+
+
+	if (priv->calltip_query_file)
+		g_object_unref (priv->calltip_query_file);
+	priv->calltip_query_file = NULL;
+		                
+	if (priv->calltip_query_system)
+		g_object_unref (priv->calltip_query_system);
+	priv->calltip_query_system = NULL;
+	
+	if (priv->calltip_query_project)
+		g_object_unref (priv->calltip_query_project);
+	priv->calltip_query_project = NULL;
+	
+	if (priv->ac_query_file)
+		g_object_unref (priv->ac_query_file);
+	priv->ac_query_file = NULL;
+	
+	if (priv->ac_query_system)
+		g_object_unref (priv->ac_query_system);
+	priv->ac_query_system = NULL;
+		                
+	if (priv->ac_query_project)
+		g_object_unref (priv->ac_query_project);
+	priv->ac_query_project = NULL;
+		                
+	if (priv->query_members)
+		g_object_unref (priv->query_members);
+	priv->query_members = NULL;
+
+	engine_parser_deinit ();
+	
 	g_free (assist->priv);
 	G_OBJECT_CLASS (cpp_java_assist_parent_class)->finalize (object);
 }
diff --git a/plugins/language-support-cpp-java/cxxparser/engine-parser-priv.h b/plugins/language-support-cpp-java/cxxparser/engine-parser-priv.h
index 1b2ea5b..0a3ff16 100644
--- a/plugins/language-support-cpp-java/cxxparser/engine-parser-priv.h
+++ b/plugins/language-support-cpp-java/cxxparser/engine-parser-priv.h
@@ -44,6 +44,7 @@ public:
 
 	/* setter for the IAnjutaSymbolManager. */
 	void setSymbolManager (IAnjutaSymbolManager *manager);
+	void unsetSymbolManager ();
 
 	void getNearestClassInCurrentScopeChainByFileLine (const char* full_file_path,
 	                                                   unsigned long linenum,
diff --git a/plugins/language-support-cpp-java/cxxparser/engine-parser.cpp b/plugins/language-support-cpp-java/cxxparser/engine-parser.cpp
index 6b40a83..0aadbc3 100644
--- a/plugins/language-support-cpp-java/cxxparser/engine-parser.cpp
+++ b/plugins/language-support-cpp-java/cxxparser/engine-parser.cpp
@@ -116,6 +116,26 @@ EngineParser::parseExpression(const string &in)
 	return parse_expression (in.c_str ());	
 }
 
+void
+EngineParser::unsetSymbolManager ()
+{
+	if (_query_scope)
+		g_object_unref (_query_scope);
+	_query_scope = NULL;
+
+	if (_query_search)
+		g_object_unref (_query_search);
+	_query_search = NULL;
+
+	if (_query_search_in_scope)
+		g_object_unref (_query_search_in_scope);
+	_query_search_in_scope = NULL;
+
+	if (_query_parent_scope)
+		g_object_unref (_query_parent_scope);
+	_query_parent_scope = NULL;
+}
+
 void 
 EngineParser::setSymbolManager (IAnjutaSymbolManager *manager)
 {
@@ -819,6 +839,12 @@ engine_parser_init (IAnjutaSymbolManager * manager)
 	EngineParser::getInstance ()->setSymbolManager (manager);
 }
 
+void
+engine_parser_deinit ()
+{
+	EngineParser::getInstance ()->unsetSymbolManager ();
+}
+
 IAnjutaIterable *
 engine_parser_process_expression (const gchar *stmt, const gchar * above_text,
     const gchar * full_file_path, gulong linenum)
diff --git a/plugins/language-support-cpp-java/cxxparser/engine-parser.h b/plugins/language-support-cpp-java/cxxparser/engine-parser.h
index d0e3644..85ce8f3 100644
--- a/plugins/language-support-cpp-java/cxxparser/engine-parser.h
+++ b/plugins/language-support-cpp-java/cxxparser/engine-parser.h
@@ -28,6 +28,8 @@ extern "C" {
 
 void engine_parser_init (IAnjutaSymbolManager * manager);
 
+void engine_parser_deinit ();
+	
 /**
  * The function parse the C++ statement, try to get the type of objects to be
  * completed and returns an iterator with those symbols.
diff --git a/plugins/symbol-db/plugin.c b/plugins/symbol-db/plugin.c
index 1380454..59d5df4 100644
--- a/plugins/symbol-db/plugin.c
+++ b/plugins/symbol-db/plugin.c
@@ -2328,6 +2328,13 @@ symbol_db_deactivate (AnjutaPlugin *plugin)
 		sdb_plugin->update_timer = NULL;
 	}
 
+	/* destroy search query */
+	if (sdb_plugin->search_query)
+	{
+		g_object_unref (sdb_plugin->search_query);
+	}
+	sdb_plugin->search_query = NULL;
+	
 	/* destroy objects */
 	if (sdb_plugin->sdbe_project) 
 	{
diff --git a/plugins/symbol-db/symbol-db-query.c b/plugins/symbol-db/symbol-db-query.c
index 2b2ac71..a062519 100644
--- a/plugins/symbol-db/symbol-db-query.c
+++ b/plugins/symbol-db/symbol-db-query.c
@@ -62,6 +62,7 @@ struct _SymbolDBQueryPriv {
 
 	SymbolDBEngine *dbe_system;
 	SymbolDBEngine *dbe_project;
+	/* a reference to dbe_system or dbe_project */
 	SymbolDBEngine *dbe_selected;
 	
 	/* Param holders */
@@ -764,7 +765,7 @@ sdb_query_dispose (GObject *object)
 		g_signal_handlers_disconnect_by_func (priv->dbe_selected,
 		                                      on_sdb_query_dbe_disconnected,
 		                                      object);
-		g_object_unref (priv->dbe_selected);
+		/* no need to unref dbe_selected */
 		priv->dbe_selected = NULL;
 	}
 	if (priv->dbe_system)
@@ -872,7 +873,9 @@ sdb_query_set_property (GObject *object, guint prop_id, const GValue *value, GPa
 				priv->dbe_selected = priv->dbe_system;
 				break;
 		}
-		g_object_ref (priv->dbe_selected);
+		g_object_ref (priv->dbe_project);
+		g_object_ref (priv->dbe_system);
+			
 		g_signal_connect (priv->dbe_selected, "scan-end",
 		                  G_CALLBACK (on_sdb_query_dbe_scan_end), query);
 		g_signal_connect (priv->dbe_selected, "db-connected",



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