changeset 19143:3bec25803a00

Fix a potential crash if the file-selector window is closed after the pref-window.
author Sadrul Habib Chowdhury <imadil@gmail.com>
date Sat, 07 Jul 2007 01:30:42 +0000
parents 5f2bcb110f00
children 0e30dfac1f46
files finch/gntsound.c
diffstat 1 files changed, 14 insertions(+), 2 deletions(-) [+]
line wrap: on
line diff
--- a/finch/gntsound.c	Sat Jul 07 01:17:19 2007 +0000
+++ b/finch/gntsound.c	Sat Jul 07 01:30:42 2007 +0000
@@ -70,6 +70,7 @@
 	GntWidget *volume;
 	GntWidget *events;
 	GntWidget *window;
+	GntWidget *selector;
 } SoundPrefDialog;
 
 SoundPrefDialog *pref_dialog;
@@ -650,14 +651,24 @@
 	GntFileSel *sel = GNT_FILE_SEL(w);
 	PurpleSoundEventID id = GPOINTER_TO_INT(gnt_tree_get_selection_data(GNT_TREE(pref_dialog->events)));
 	FinchSoundEvent * event = &sounds[id];
+	char *path = NULL;
 
 	gnt_file_sel_set_current_location(sel,
-			(event && event->file) ? g_path_get_dirname(event->file) : purple_home_dir());
+			(event && event->file) ? (path = g_path_get_dirname(event->file))
+				: purple_home_dir());
 
 	g_signal_connect_swapped(G_OBJECT(sel->cancel),"activate",G_CALLBACK(gnt_widget_destroy),sel);
 	g_signal_connect(G_OBJECT(sel), "file_selected", G_CALLBACK(file_cb), event);
+	g_signal_connect_swapped(G_OBJECT(sel), "destroy", G_CALLBACK(g_nullify_pointer), &pref_dialog->selector);
+
+	/* If there's an already open file-selector, close that one. */
+	if (pref_dialog->selector)
+		gnt_widget_destroy(pref_dialog->selector);
+
+	pref_dialog->selector = w;
 
 	gnt_widget_show(w);
+	g_free(path);
 }
 
 static void
@@ -669,6 +680,8 @@
 		FinchSoundEvent * e = &sounds[id];
 		g_free(e->file);
 	}
+	if (pref_dialog->selector)
+		gnt_widget_destroy(pref_dialog->selector);
 	g_free(pref_dialog);
 	pref_dialog = NULL;
 }
@@ -818,7 +831,6 @@
 	gnt_box_add_widget(GNT_BOX(box),button);
 	gnt_box_add_widget(GNT_BOX(win),box);
 
-
 	g_signal_connect(G_OBJECT(win),"destroy",G_CALLBACK(release_pref_dialog),NULL);
 
 	gnt_widget_show(win);