changeset 1698:bfe04f01de5e

fixed destroying of menu data Make sure that menu destroy functions do not access parent widget structures that are already destroyed There are 2 ways to achieve this: - use g_signal_handlers_disconnect_matched() like in vf_destroy_cb() - use separate data structure passed to *_popup_menu_destroy_cb() like in img-view.
author nadvornik
date Tue, 21 Jul 2009 14:17:01 +0000
parents 219e1ba3ae30
children 81ccb9cf7ef5
files src/dupe.c src/dupe.h src/img-view.c src/layout_image.c src/pan-types.h src/pan-view.c src/search.c src/typedefs.h
diffstat 8 files changed, 40 insertions(+), 54 deletions(-) [+]
line wrap: on
line diff
--- a/src/dupe.c	Sat Jul 18 08:16:54 2009 +0000
+++ b/src/dupe.c	Tue Jul 21 14:17:01 2009 +0000
@@ -2207,10 +2207,9 @@
 
 static void dupe_menu_popup_destroy_cb(GtkWidget *widget, gpointer data)
 {
-	DupeWindow *dw = data;
-
-	filelist_free(dw->editmenu_fd_list);
-	dw->editmenu_fd_list = NULL;
+	GList *editmenu_fd_list = data;
+
+	filelist_free(editmenu_fd_list);
 }	
 
 static GList *dupe_window_get_fd_list(DupeWindow *dw)
@@ -2234,12 +2233,11 @@
 	GtkWidget *menu;
 	GtkWidget *item;
 	gint on_row;
+	GList *editmenu_fd_list;
 
 	on_row = (di != NULL);
 
 	menu = popup_menu_short_lived();
-	g_signal_connect(G_OBJECT(menu), "destroy",
-			 G_CALLBACK(dupe_menu_popup_destroy_cb), dw);
 
 	menu_item_add_sensitive(menu, _("_View"), on_row,
 				G_CALLBACK(dupe_menu_view_cb), dw);
@@ -2256,8 +2254,10 @@
 				G_CALLBACK(dupe_menu_select_dupes_set2_cb), dw);
 	menu_item_add_divider(menu);
 	
-	dw->editmenu_fd_list = dupe_window_get_fd_list(dw);
-	submenu_add_edit(menu, &item, G_CALLBACK(dupe_menu_edit_cb), dw, dw->editmenu_fd_list);
+	editmenu_fd_list = dupe_window_get_fd_list(dw);
+	g_signal_connect(G_OBJECT(menu), "destroy",
+			 G_CALLBACK(dupe_menu_popup_destroy_cb), editmenu_fd_list);
+	submenu_add_edit(menu, &item, G_CALLBACK(dupe_menu_edit_cb), dw, editmenu_fd_list);
 	if (!on_row) gtk_widget_set_sensitive(item, FALSE);
 	menu_item_add_stock_sensitive(menu, _("Add to new collection"), GTK_STOCK_INDEX, on_row,
 				G_CALLBACK(dupe_menu_collection_cb), dw);
--- a/src/dupe.h	Sat Jul 18 08:16:54 2009 +0000
+++ b/src/dupe.h	Tue Jul 21 14:17:01 2009 +0000
@@ -109,10 +109,6 @@
 	GtkWidget *second_status_label;
 
 	gboolean color_frozen;
-	
-	/* file list for edit menu */
-	GList *editmenu_fd_list;
-
 };
 
 
--- a/src/img-view.c	Sat Jul 18 08:16:54 2009 +0000
+++ b/src/img-view.c	Tue Jul 21 14:17:01 2009 +0000
@@ -49,9 +49,6 @@
 
 	GList *list;
 	GList *list_pointer;
-
-	/* file list for edit menu */
-	GList *editmenu_fd_list;
 };
 
 
@@ -1238,10 +1235,9 @@
 
 static void view_popup_menu_destroy_cb(GtkWidget *widget, gpointer data)
 {
-	ViewWindow *vw = data;
+	GList *editmenu_fd_list = data;
 
-	filelist_free(vw->editmenu_fd_list);
-	vw->editmenu_fd_list = NULL;
+	filelist_free(editmenu_fd_list);
 }		
 
 static GList *view_window_get_fd_list(ViewWindow *vw)
@@ -1262,11 +1258,10 @@
 {
 	GtkWidget *menu;
 	GtkWidget *item;
+	GList *editmenu_fd_list;
 
 	menu = popup_menu_short_lived();
 
-	g_signal_connect(G_OBJECT(menu), "destroy",
-			 G_CALLBACK(view_popup_menu_destroy_cb), vw);
 
 	menu_item_add_stock(menu, _("Zoom _in"), GTK_STOCK_ZOOM_IN, G_CALLBACK(view_zoom_in_cb), vw);
 	menu_item_add_stock(menu, _("Zoom _out"), GTK_STOCK_ZOOM_OUT, G_CALLBACK(view_zoom_out_cb), vw);
@@ -1274,8 +1269,10 @@
 	menu_item_add_stock(menu, _("Fit image to _window"), GTK_STOCK_ZOOM_FIT, G_CALLBACK(view_zoom_fit_cb), vw);
 	menu_item_add_divider(menu);
 
- 	vw->editmenu_fd_list = view_window_get_fd_list(vw);
-	item = submenu_add_edit(menu, NULL, G_CALLBACK(view_edit_cb), vw, vw->editmenu_fd_list);
+ 	editmenu_fd_list = view_window_get_fd_list(vw);
+	g_signal_connect(G_OBJECT(menu), "destroy",
+			 G_CALLBACK(view_popup_menu_destroy_cb), editmenu_fd_list);
+	item = submenu_add_edit(menu, NULL, G_CALLBACK(view_edit_cb), vw, editmenu_fd_list);
 	menu_item_add_divider(item);
 	menu_item_add(item, _("Set as _wallpaper"), G_CALLBACK(view_wallpaper_cb), vw);
 
--- a/src/layout_image.c	Sat Jul 18 08:16:54 2009 +0000
+++ b/src/layout_image.c	Tue Jul 21 14:17:01 2009 +0000
@@ -449,11 +449,10 @@
 
 static void layout_image_popup_menu_destroy_cb(GtkWidget *widget, gpointer data)
 {
-	LayoutWindow *lw = data;
+	GList *editmenu_fd_list = data;
 
-	filelist_free(lw->editmenu_fd_list);
-	lw->editmenu_fd_list = NULL;
-}	
+	filelist_free(editmenu_fd_list);
+}
 
 static GList *layout_image_get_fd_list(LayoutWindow *lw)
 {
@@ -473,13 +472,12 @@
 	GtkWidget *submenu;
 	const gchar *path;
 	gboolean fullscreen;
+	GList *editmenu_fd_list;
 
 	path = layout_image_get_path(lw);
 	fullscreen = layout_image_full_screen_active(lw);
 
 	menu = popup_menu_short_lived();
-	g_signal_connect(G_OBJECT(menu), "destroy",
-			 G_CALLBACK(layout_image_popup_menu_destroy_cb), lw);
 
 	menu_item_add_stock(menu, _("Zoom _in"), GTK_STOCK_ZOOM_IN, G_CALLBACK(li_pop_menu_zoom_in_cb), lw);
 	menu_item_add_stock(menu, _("Zoom _out"), GTK_STOCK_ZOOM_OUT, G_CALLBACK(li_pop_menu_zoom_out_cb), lw);
@@ -487,8 +485,10 @@
 	menu_item_add_stock(menu, _("Fit image to _window"), GTK_STOCK_ZOOM_FIT, G_CALLBACK(li_pop_menu_zoom_fit_cb), lw);
 	menu_item_add_divider(menu);
 
-	lw->editmenu_fd_list = layout_image_get_fd_list(lw);
-	submenu = submenu_add_edit(menu, &item, G_CALLBACK(li_pop_menu_edit_cb), lw, lw->editmenu_fd_list);
+	editmenu_fd_list = layout_image_get_fd_list(lw);
+	g_signal_connect(G_OBJECT(menu), "destroy",
+			 G_CALLBACK(layout_image_popup_menu_destroy_cb), editmenu_fd_list);
+	submenu = submenu_add_edit(menu, &item, G_CALLBACK(li_pop_menu_edit_cb), lw, editmenu_fd_list);
 	if (!path) gtk_widget_set_sensitive(item, FALSE);
 	menu_item_add_divider(submenu);
 	menu_item_add(submenu, _("Set as _wallpaper"), G_CALLBACK(li_pop_menu_wallpaper_cb), lw);
--- a/src/pan-types.h	Sat Jul 18 08:16:54 2009 +0000
+++ b/src/pan-types.h	Tue Jul 21 14:17:01 2009 +0000
@@ -225,9 +225,6 @@
 	PanItem *search_pi;
 
 	gint idle_id;
-	
-	/* file list for edit menu */
-	GList *editmenu_fd_list;
 };
 
 typedef struct _PanGrid PanGrid;
--- a/src/pan-view.c	Sat Jul 18 08:16:54 2009 +0000
+++ b/src/pan-view.c	Tue Jul 21 14:17:01 2009 +0000
@@ -2778,10 +2778,9 @@
 
 static void pan_popup_menu_destroy_cb(GtkWidget *widget, gpointer data)
 {
-	PanWindow *pw = data;
-
-	filelist_free(pw->editmenu_fd_list);
-	pw->editmenu_fd_list = NULL;
+	GList *editmenu_fd_list = data;
+
+	filelist_free(editmenu_fd_list);
 }
 
 static GList *pan_view_get_fd_list(PanWindow *pw)
@@ -2800,6 +2799,7 @@
 	GtkWidget *submenu;
 	GtkWidget *item;
 	gboolean active;
+	GList *editmenu_fd_list;
 
 	active = (pw->click_pi != NULL);
 
@@ -2815,8 +2815,11 @@
 			    G_CALLBACK(pan_zoom_1_1_cb), pw);
 	menu_item_add_divider(menu);
 
-	pw->editmenu_fd_list = pan_view_get_fd_list(pw);
-	submenu_add_edit(menu, &item, G_CALLBACK(pan_edit_cb), pw, pw->editmenu_fd_list);
+	editmenu_fd_list = pan_view_get_fd_list(pw);
+	g_signal_connect(G_OBJECT(menu), "destroy",
+			 G_CALLBACK(pan_popup_menu_destroy_cb), editmenu_fd_list);
+
+	submenu_add_edit(menu, &item, G_CALLBACK(pan_edit_cb), pw, editmenu_fd_list);
 	gtk_widget_set_sensitive(item, active);
 	
 	menu_item_add_stock_sensitive(menu, _("View in _new window"), GTK_STOCK_NEW, active,
--- a/src/search.c	Sat Jul 18 08:16:54 2009 +0000
+++ b/src/search.c	Tue Jul 21 14:17:01 2009 +0000
@@ -190,10 +190,6 @@
 	ThumbLoader *thumb_loader;
 	gboolean thumb_enable;
 	FileData *thumb_fd;
-
-	/* file list for edit menu */
-	GList *editmenu_fd_list;
-
 };
 
 typedef struct _MatchFileData MatchFileData;
@@ -984,20 +980,18 @@
 
 static void search_result_menu_destroy_cb(GtkWidget *widget, gpointer data)
 {
-	SearchData *sd = data;
-
-	filelist_free(sd->editmenu_fd_list);
-	sd->editmenu_fd_list = NULL;
+	GList *editmenu_fd_list = data;
+
+	filelist_free(editmenu_fd_list);
 }
 
 static GtkWidget *search_result_menu(SearchData *sd, gboolean on_row, gboolean empty)
 {
 	GtkWidget *menu;
 	GtkWidget *item;
+	GList *editmenu_fd_list;
 
 	menu = popup_menu_short_lived();
-	g_signal_connect(G_OBJECT(menu), "destroy",
-			 G_CALLBACK(search_result_menu_destroy_cb), sd);
 
 	menu_item_add_sensitive(menu, _("_View"), on_row,
 				G_CALLBACK(sr_menu_view_cb), sd);
@@ -1010,8 +1004,10 @@
 				G_CALLBACK(sr_menu_select_none_cb), sd);
 	menu_item_add_divider(menu);
 
-	sd->editmenu_fd_list = search_result_selection_list(sd);
-	submenu_add_edit(menu, &item, G_CALLBACK(sr_menu_edit_cb), sd, sd->editmenu_fd_list);
+	editmenu_fd_list = search_result_selection_list(sd);
+	g_signal_connect(G_OBJECT(menu), "destroy",
+			 G_CALLBACK(search_result_menu_destroy_cb), editmenu_fd_list);
+	submenu_add_edit(menu, &item, G_CALLBACK(sr_menu_edit_cb), sd, editmenu_fd_list);
 	if (!on_row) gtk_widget_set_sensitive(item, FALSE);
 	menu_item_add_stock_sensitive(menu, _("Add to new collection"), GTK_STOCK_INDEX, on_row,
 				      G_CALLBACK(sr_menu_collection_cb), sd);
--- a/src/typedefs.h	Sat Jul 18 08:16:54 2009 +0000
+++ b/src/typedefs.h	Tue Jul 21 14:17:01 2009 +0000
@@ -666,9 +666,6 @@
 //	gint bar_width;
 
 	GtkWidget *exif_window;
-
-	/* file list for edit menu */
-	GList *editmenu_fd_list;
 };
 
 struct _ViewDir