changeset 1413:3bc4967aaa57

Use dynamic allocation for editor key passed to various callbacks.
author zas_
date Wed, 11 Mar 2009 17:38:20 +0000
parents 5a534e1501e1
children 6ce1f7171d48
files src/bar_sort.c src/menu.c src/view_dir.c
diffstat 3 files changed, 36 insertions(+), 16 deletions(-) [+]
line wrap: on
line diff
--- a/src/bar_sort.c	Tue Mar 10 22:52:12 2009 +0000
+++ b/src/bar_sort.c	Wed Mar 11 17:38:20 2009 +0000
@@ -66,7 +66,7 @@
 
 	SortModeType mode;
 	SortActionType action;
-	const gchar *filter_key;
+	gchar *filter_key;
 	
 	SortSelectionType selection;
 
@@ -355,7 +355,7 @@
 	if (action == BAR_SORT_FILTER)
 		{
 		if (!filter_key) filter_key = "";
-		sd->filter_key = filter_key;
+		sd->filter_key = g_strdup(filter_key);
 		}
 	else
 		{
@@ -546,11 +546,17 @@
 
 	bar_sort_add_close(sd);
 
+	g_free(sd->filter_key);
 	g_free(sd->undo_src);
 	g_free(sd->undo_dest);
 	g_free(sd);
 }
 
+static void bar_sort_edit_button_free(gpointer data)
+{
+	g_free(data);
+}
+
 static GtkWidget *bar_sort_new(LayoutWindow *lw, SortActionType action, SortModeType mode, SortSelectionType selection, const gchar *filter_key)
 {
 	SortData *sd;
@@ -615,24 +621,26 @@
 		{
 		GtkWidget *button;
 		EditorDescription *editor = work->data;
-		work = work->next;
+		gchar *key;
 		gboolean select = FALSE;
-		
+
+		work = work->next;
+			
 		if (!editor_is_filter(editor->key)) continue;
-
-		if (sd->action == BAR_SORT_FILTER && strcmp(editor->key, filter_key) == 0)
+		
+		key = g_strdup(editor->key);
+		if (sd->action == BAR_SORT_FILTER && strcmp(key, filter_key) == 0)
 			{
-			bar_sort_set_action(sd, sd->action, editor->key);
+			bar_sort_set_action(sd, sd->action, key);
 			select = TRUE;
 			have_filter = TRUE;
 			}
-
+		
 		button = pref_radiobutton_new(sd->folder_group, buttongrp,
 					      editor->name, select,
 					      G_CALLBACK(bar_sort_set_filter_cb), sd);
 
-
-		g_object_set_data(G_OBJECT(button), "filter_key", editor->key);
+		g_object_set_data_full(G_OBJECT(button), "filter_key", key, bar_sort_edit_button_free);
 		}
 	g_list_free(editors_list);
 	
--- a/src/menu.c	Tue Mar 10 22:52:12 2009 +0000
+++ b/src/menu.c	Wed Mar 11 17:38:20 2009 +0000
@@ -64,6 +64,10 @@
  * edit menu
  *-----------------------------------------------------------------------------
  */
+static void edit_item_destroy_cb(GtkWidget *widget, gpointer data)
+{
+	g_free(data);
+}
 
 static void add_edit_items(GtkWidget *menu, GCallback func, GList *fd_list)
 {
@@ -81,11 +85,15 @@
 
 		if (active)
 			{
+			GtkWidget *item;
 			const gchar *stock_id = NULL;
-			if (editor->icon && register_theme_icon_as_stock(editor->key, editor->icon))
-				stock_id = editor->key;
+			gchar *key = g_strdup(editor->key);
 
-			menu_item_add_stock(menu, editor->name, stock_id, func, editor->key);
+			if (editor->icon && register_theme_icon_as_stock(key, editor->icon))
+				stock_id = key;
+
+			item = menu_item_add_stock(menu, editor->name, stock_id, func, key);
+			g_signal_connect(G_OBJECT(item), "destroy", G_CALLBACK(edit_item_destroy_cb), key);
 			}
 		}
 	
--- a/src/view_dir.c	Tue Mar 10 22:52:12 2009 +0000
+++ b/src/view_dir.c	Wed Mar 11 17:38:20 2009 +0000
@@ -330,7 +330,10 @@
 	file_util_start_filter_from_filelist(key, list, path, vd->widget);
 }
 
-
+static void vd_drop_menu_edit_item_free(gpointer data)
+{
+	g_free(data);
+}
 
 GtkWidget *vd_drop_menu(ViewDir *vd, gint active)
 {
@@ -350,12 +353,13 @@
 		{
 		GtkWidget *item;
 		const EditorDescription *editor = work->data;
+		gchar *key;
 		work = work->next;
 		
 		if (!editor_is_filter(editor->key)) continue;
+		key = g_strdup(editor->key);
 		item = menu_item_add_sensitive(menu, editor->name, active, G_CALLBACK(vd_drop_menu_filter_cb), vd);
-
-		g_object_set_data(G_OBJECT(item), "filter_key", editor->key);
+		g_object_set_data_full(G_OBJECT(item), "filter_key", key, vd_drop_menu_edit_item_free);
 		}
 	
 	g_list_free(editors_list);