Fix a memory leak from not freeing the ui-info hashtable on exit.

Sat, 11 Aug 2007 09:20:36 +0000

author
Sadrul Habib Chowdhury <sadrul@pidgin.im>
date
Sat, 11 Aug 2007 09:20:36 +0000
changeset 19239
a6866f1419c4
parent 19238
12d1d54df9ed
child 19317
61e0384e95d1

Fix a memory leak from not freeing the ui-info hashtable on exit.

finch/finch.c file | annotate | diff | comparison | revisions
--- a/finch/finch.c	Sat Aug 11 08:55:32 2007 +0000
+++ b/finch/finch.c	Sat Aug 11 09:20:36 2007 +0000
@@ -55,16 +55,10 @@
 	purple_debug_set_ui_ops(finch_debug_get_ui_ops());
 }
 
-/* XXX: this "leaks" a hashtable on shutdown.  I'll let
- * the finch guys decide if they want to go through the trouble
- * of properly freeing it, since their quit function doesn't
- * live in this file */
-
 static GHashTable *ui_info = NULL;
-
 static GHashTable *finch_ui_get_info()
 {
-	if(NULL == ui_info) {
+	if (ui_info == NULL) {
 		ui_info = g_hash_table_new(g_str_hash, g_str_equal);
 
 		g_hash_table_insert(ui_info, "name", (char*)_("Finch"));
@@ -74,12 +68,20 @@
 	return ui_info;
 }
 
+static void
+finch_quit(void)
+{
+	gnt_ui_uninit();
+	if (ui_info)
+		g_hash_table_destroy(ui_info);
+}
+
 static PurpleCoreUiOps core_ops =
 {
 	finch_prefs_init,
 	debug_init,
 	gnt_ui_init,
-	gnt_ui_uninit,
+	finch_quit,
 	finch_ui_get_info,
 
 	/* padding */
@@ -396,7 +398,17 @@
 	return 1;
 }
 
-int main(int argc, char **argv)
+static gboolean gnt_start(int *argc, char ***argv)
+{
+	/* Initialize the libpurple stuff */
+	if (!init_libpurple(*argc, *argv))
+		return FALSE;
+ 
+	purple_blist_show();
+	return TRUE;
+}
+
+int main(int argc, char *argv[])
 {
 	signal(SIGPIPE, SIG_IGN);
 
@@ -405,11 +417,10 @@
 	g_set_application_name(_("Finch"));
 #endif
 
-	/* Initialize the libpurple stuff */
-	if (!init_libpurple(argc, argv))
-		return 0;
- 
-	purple_blist_show();
+	gnt_init();
+
+	gnt_start(&argc, &argv);
+
 	gnt_main();
 
 #ifdef STANDALONE

mercurial