From 42eabfd7f44835017b331f5ed9670d8cde35d7e1 Mon Sep 17 00:00:00 2001 Message-Id: <42eabfd7f44835017b331f5ed9670d8cde35d7e1.1714037283.git.mdw@distorted.org.uk> From: Mark Wooding Date: Sun, 15 Nov 2009 21:15:38 +0000 Subject: [PATCH] Some missing D+D memory management Organization: Straylight/Edgeware From: Richard Kettlewell --- disobedience/multidrag.c | 23 +++++++++++++---------- disobedience/queue-generic.c | 4 ++++ 2 files changed, 17 insertions(+), 10 deletions(-) diff --git a/disobedience/multidrag.c b/disobedience/multidrag.c index 95dcbb2..8b28c94 100644 --- a/disobedience/multidrag.c +++ b/disobedience/multidrag.c @@ -76,11 +76,11 @@ static void block_selection(GtkWidget *w, gboolean block, int *where = g_object_get_data(G_OBJECT(w), "multidrag-where"); if(!where) { where = g_malloc(2 * sizeof (int)); - g_object_set_data(G_OBJECT(w), "multidrag-where", where); + g_object_set_data_full(G_OBJECT(w), "multidrag-where", where, + g_free); } where[0] = x; where[1] = y; - // TODO release 'where' when object is destroyed } static gboolean multidrag_button_press_event(GtkWidget *w, @@ -96,21 +96,22 @@ static gboolean multidrag_button_press_event(GtkWidget *w, if(event->state & GDK_MODIFIER_MASK) return FALSE; /* We are only interested if a well-defined path is clicked */ - GtkTreePath *path; + GtkTreePath *path = NULL; if(!gtk_tree_view_get_path_at_pos(GTK_TREE_VIEW(w), event->x, event->y, &path, NULL, NULL, NULL)) return FALSE; - //gtk_widget_grab_focus(w); // TODO why?? /* We are only interested if a selected row is clicked */ GtkTreeSelection *s = gtk_tree_view_get_selection(GTK_TREE_VIEW(w)); - if(!gtk_tree_selection_path_is_selected(s, path)) - return FALSE; - /* We block subsequent selection changes and remember where the - * click was */ - block_selection(w, FALSE, event->x, event->y); + if(gtk_tree_selection_path_is_selected(s, path)) { + /* We block subsequent selection changes and remember where the + * click was */ + block_selection(w, FALSE, event->x, event->y); + } + if(path) + gtk_tree_path_free(path); return FALSE; /* propagate */ } @@ -129,7 +130,7 @@ static gboolean multidrag_button_release_event(GtkWidget *w, if(x == event->x && y == event->y) { // If the up-click is at the same location as the down-click, // it's not a drag. - GtkTreePath *path; + GtkTreePath *path = NULL; GtkTreeViewColumn *col; if(gtk_tree_view_get_path_at_pos(GTK_TREE_VIEW(w), event->x, event->y, @@ -138,6 +139,8 @@ static gboolean multidrag_button_release_event(GtkWidget *w, NULL, NULL)) { gtk_tree_view_set_cursor(GTK_TREE_VIEW(w), path, col, FALSE); } + if(path) + gtk_tree_path_free(path); } } return FALSE; /* propagate */ diff --git a/disobedience/queue-generic.c b/disobedience/queue-generic.c index a2aa8ac..82bd939 100644 --- a/disobedience/queue-generic.c +++ b/disobedience/queue-generic.c @@ -438,6 +438,8 @@ void ql_new_queue(struct queuelike *ql, * This is used by ql_drag_motion() and ql_drag_data_received() to identify a * drop would or does land. It's important that they use the same code since * otherwise the visual feedback can be inconsistent with the actual effect! + * + * Remember to free the returned path. */ static GtkTreePath *ql_drop_path(GtkWidget *w, GtkTreeModel *model, @@ -718,6 +720,8 @@ static void ql_drag_data_received(GtkWidget attribute((unused)) *w, ql->drop(ql, tracks->nvec, tracks->vec, NULL, q); break; } + if(path) + gtk_tree_path_free(path); } /** @brief Initialize a @ref queuelike */ -- [mdw]