[gnome-software] back button: Ensure that the back entry focus widget is valid



commit 953f653512b3aacc3f6b99058f396dc979aa0734
Author: Rafal Luzynski <digitalfreak lingonborough com>
Date:   Thu Feb 26 02:34:41 2015 +0100

    back button: Ensure that the back entry focus widget is valid
    
    Instead of g_object_ref() use g_object_add_weak_pointer()
    to monitor the finalization of the focus widget while still
    allowing it to be finalized. This fixes a crash on the Back
    button when the old focus widget cannot accept the focus
    because it has been removed, for example when it is a list box
    row which has been removed from the list box.
    
    https://bugzilla.gnome.org/show_bug.cgi?id=744879

 src/gs-shell.c |   12 +++++++-----
 1 files changed, 7 insertions(+), 5 deletions(-)
---
diff --git a/src/gs-shell.c b/src/gs-shell.c
index 7e18a0a..f1185d8 100644
--- a/src/gs-shell.c
+++ b/src/gs-shell.c
@@ -235,14 +235,14 @@ save_back_entry (GsShell *shell)
 {
        GsShellPrivate *priv = shell->priv;
        BackEntry *entry;
-       GtkWidget *focus;
 
        entry = g_new0 (BackEntry, 1);
        entry->mode = priv->mode;
 
-       focus = gtk_window_get_focus (priv->main_window);
-       if (focus != NULL)
-               entry->focus = g_object_ref (focus);
+       entry->focus = gtk_window_get_focus (priv->main_window);
+       if (entry->focus != NULL)
+               g_object_add_weak_pointer (G_OBJECT (entry->focus),
+                                          (gpointer *) &entry->focus);
 
        if (priv->mode == GS_SHELL_MODE_CATEGORY) {
                entry->category = gs_shell_category_get_category (priv->shell_category);
@@ -259,7 +259,9 @@ save_back_entry (GsShell *shell)
 static void
 free_back_entry (BackEntry *entry)
 {
-       g_clear_object (&entry->focus);
+       if (entry->focus)
+               g_object_remove_weak_pointer(G_OBJECT (entry->focus),
+                                            (gpointer *) &entry->focus);
        g_clear_object (&entry->category);
        g_clear_object (&entry->app);
        g_free (entry);


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]