Bug fix: gtktreeitem.c



After much digging (and some upgrades, particularly binutils), I have
nailed the gtk_tree_item_remove_subtree() segfault bug. Code snippet
(gtktreeitem.c:994):

  g_return_if_fail (item->subtree != NULL);
  
  if (GTK_TREE (item->subtree)->children)
    gtk_tree_remove_items (GTK_TREE (item->subtree), 
			   GTK_TREE (item->subtree)->children);

  if (GTK_WIDGET_MAPPED (item->subtree))
    gtk_widget_unmap (item->subtree);
 
However, after gtk_tree_remove_items(), item->subtree can now be NULL,
which causes GTK_WIDGET_MAPPED to be passed a NULL pointer, producing the
segfault. The attached patch tests for this condition. You still get
warnings when trying to remove the minus pixmap and add the plus pixmap,
but this has no harmful side-effects. This fixes, at least, the browse.py
example with pygtk-0.4.1. I've never found any other examples of code
which use ...remove_subtree().

-- 
Andy Dustman                                              Charles Babbage:
ComStar Communications Corp.                          He never used Linux,
(770) 333-8779 | PGP KeyID=0xC72F3F1D                  and now, he's dead.
--- gtk+-1.0.0/gtk/gtktreeitem.c.orig	Sun Apr 12 22:02:13 1998
+++ gtk+-1.0.0/gtk/gtktreeitem.c	Tue Apr 21 20:20:11 1998
@@ -997,15 +997,18 @@
     gtk_tree_remove_items (GTK_TREE (item->subtree), 
 			   GTK_TREE (item->subtree)->children);
   
-  if (GTK_WIDGET_MAPPED (item->subtree))
-    gtk_widget_unmap (item->subtree);
+  if (item->subtree != NULL) {
+    if (GTK_WIDGET_MAPPED (item->subtree))
+      gtk_widget_unmap (item->subtree);
+    
+    gtk_widget_unparent (item->subtree);
+
+    item->subtree = NULL;
+  }
 
-  gtk_widget_unparent (item->subtree);
-  
   if (item->pixmaps_box)
     gtk_widget_hide (item->pixmaps_box);
-  
-  item->subtree = NULL;
+
   item->expanded = FALSE;
   if (item->pixmaps_box)
     {


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