[nautilus] places-sidebar: don't call gtk_tree_model_get() with an invalid path
- From: Cosimo Cecchi <cosimoc src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [nautilus] places-sidebar: don't call gtk_tree_model_get() with an invalid path
- Date: Wed, 19 Oct 2011 18:56:37 +0000 (UTC)
commit 7826dfbdc4cb9a5381b6d9845e0ba7459fcd2fe4
Author: Cosimo Cecchi <cosimoc gnome org>
Date: Wed Oct 19 14:52:09 2011 -0400
places-sidebar: don't call gtk_tree_model_get() with an invalid path
If we click on an empty area of the sidebar, we shouldn't pop up any
menu at all anyway, which is what this commit changes.
Previously, we would have tried to get a GtkTreePath for the currently
selected point and an iter for that (invalid) path, which would lead to
gtk_tree_model_get() segfaulting on an invalid iter.
https://bugzilla.gnome.org/show_bug.cgi?id=662218
src/nautilus-places-sidebar.c | 53 ++++++++++++++++++----------------------
1 files changed, 24 insertions(+), 29 deletions(-)
---
diff --git a/src/nautilus-places-sidebar.c b/src/nautilus-places-sidebar.c
index 61f8a6f..b133f54 100644
--- a/src/nautilus-places-sidebar.c
+++ b/src/nautilus-places-sidebar.c
@@ -1895,15 +1895,15 @@ open_shortcut_from_menu (NautilusPlacesSidebar *sidebar,
NautilusWindowOpenFlags flags)
{
GtkTreeModel *model;
- GtkTreePath *path;
GtkTreeIter iter;
+ GtkTreePath *path = NULL;
model = gtk_tree_view_get_model (sidebar->tree_view);
gtk_tree_view_get_cursor (sidebar->tree_view, &path, NULL);
- gtk_tree_model_get_iter (model, &iter, path);
-
- open_selected_bookmark (sidebar, model, &iter, flags);
+ if (path != NULL && gtk_tree_model_get_iter (model, &iter, path)) {
+ open_selected_bookmark (sidebar, model, &iter, flags);
+ }
gtk_tree_path_free (path);
}
@@ -2945,35 +2945,32 @@ static gboolean
bookmarks_button_press_event_cb (GtkWidget *widget,
GdkEventButton *event,
NautilusPlacesSidebar *sidebar)
+
{
+ GtkTreeModel *model;
+ GtkTreeView *tree_view;
+ GtkTreeIter iter;
+ GtkTreePath *path = NULL;
+ gboolean retval = FALSE;
+
if (event->type != GDK_BUTTON_PRESS) {
/* ignore multiple clicks */
return TRUE;
}
+ tree_view = GTK_TREE_VIEW (widget);
+ model = gtk_tree_view_get_model (tree_view);
+ gtk_tree_view_get_path_at_pos (tree_view, (int) event->x, (int) event->y,
+ &path, NULL, NULL, NULL);
+
+ if (path == NULL || !gtk_tree_model_get_iter (model, &iter, path)) {
+ return FALSE;
+ }
+
if (event->button == 3) {
bookmarks_popup_menu (sidebar, event);
} else if (event->button == 2) {
- GtkTreeModel *model;
- GtkTreePath *path;
- GtkTreeIter iter;
- GtkTreeView *tree_view;
NautilusWindowOpenFlags flags = 0;
- gboolean res;
-
- tree_view = GTK_TREE_VIEW (widget);
- g_assert (tree_view == sidebar->tree_view);
-
- model = gtk_tree_view_get_model (tree_view);
-
- res = gtk_tree_view_get_path_at_pos (tree_view, (int) event->x, (int) event->y,
- &path, NULL, NULL, NULL);
-
- if (!res) {
- return FALSE;
- }
-
- gtk_tree_model_get_iter (model, &iter, path);
if (g_settings_get_boolean (nautilus_preferences,
NAUTILUS_PREFERENCES_ALWAYS_USE_BROWSER)) {
@@ -2985,14 +2982,12 @@ bookmarks_button_press_event_cb (GtkWidget *widget,
}
open_selected_bookmark (sidebar, model, &iter, flags);
-
- if (path != NULL) {
- gtk_tree_path_free (path);
- return TRUE;
- }
+ retval = TRUE;
}
- return FALSE;
+ gtk_tree_path_free (path);
+
+ return retval;
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]