[gedit] notebook: prevent a crash when detaching a tab



commit cce8be14169ee6c7d212c396daca577496d1f3e4
Author: Sébastien Wilmet <swilmet gnome org>
Date:   Wed Jan 13 13:59:41 2016 +0100

    notebook: prevent a crash when detaching a tab
    
    To reproduce the crash:
    1. Have at least two tab groups, with only one tab in a tab group.
    2. Right click on the tab label (for the single tab) -> move to new
       window.
    -> the multi-notebook destroys the notebook, with a crash in
       gtk_notebook_detach_tab() on the line after the call to
       gtk_container_remove(), since it tries to access
       notebook->priv->remove_in_detach on the destroyed notebook.

 gedit/gedit-notebook.c |   13 ++++++++++++-
 1 files changed, 12 insertions(+), 1 deletions(-)
---
diff --git a/gedit/gedit-notebook.c b/gedit/gedit-notebook.c
index a4b6e8d..fcf22c3 100644
--- a/gedit/gedit-notebook.c
+++ b/gedit/gedit-notebook.c
@@ -613,10 +613,21 @@ gedit_notebook_move_tab (GeditNotebook *src,
        g_return_if_fail (src != dest);
        g_return_if_fail (GEDIT_IS_TAB (tab));
 
-       /* make sure the tab isn't destroyed while we move it */
+       /* Make sure the tab isn't destroyed while we move it. */
        g_object_ref (tab);
+
+       /* Make sure the @src notebook isn't destroyed during the tab
+        * detachment, to prevent a crash in gtk_notebook_detach_tab(). In fact,
+        * if @tab is the last tab of @src, and if @src is not the last notebook
+        * of the GeditMultiNotebook, then @src will be destroyed when
+        * gtk_container_remove() is called by gtk_notebook_detach_tab().
+        */
+       g_object_ref (src);
        gtk_notebook_detach_tab (GTK_NOTEBOOK (src), GTK_WIDGET (tab));
+       g_object_unref (src);
+
        gedit_notebook_add_tab (dest, tab, dest_position, TRUE);
+
        g_object_unref (tab);
 }
 


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