Bug 617924

Summary: python-yui crashes with segfault when using TreeItem widget
Product: [openSUSE] openSUSE 11.0 Reporter: Pranav Senthilnathan <pirhoalpha>
Component: YaST2Assignee: Klaus Kämpf <kkaempf>
Status: RESOLVED FIXED QA Contact: Jiri Srain <jsrain>
Severity: Normal    
Priority: P5 - None    
Version: Final   
Target Milestone: Future/Later   
Hardware: i586   
OS: SLES 11   
Whiteboard:
Found By: --- Services Priority:
Business Priority: Blocker: ---
Marketing QA Status: --- IT Deployment: ---

Description Pranav Senthilnathan 2010-06-28 14:30:27 UTC
User-Agent:       Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.9.0.6) Gecko/2009012700 SUSE/3.0.6-1.14 Firefox/3.0.6

When I create TreeItems, the program runs fine until the end, where is crashes with a segfault. I am using python 2.6. The yast development team thought this was most likely a dangling pointer issue. Even this simple code crashes:

import sys
sys.path.insert(0, '/usr/src/packages/BUILD/libyui-bindings-0.1.0/build/swig/python/')
import yui

item = yui.YTreeItem("root")
item2 = yui.YTreeItem(item, "Desktop")

Every other widget that I tried worked though.

Reproducible: Always

Steps to Reproduce:
1. Run following python code (change sys.path to where python bindings are):
import sys
sys.path.insert(0, '/usr/src/packages/BUILD/libyui-bindings-0.1.0/build/swig/python/')
import yui

item = yui.YTreeItem("root")
item2 = yui.YTreeItem(item, "Desktop")
Actual Results:  
segmentation fault

Expected Results:  
error free exit

Yast developers said this is probably a dangling pointer issue or at least deals with memory ownership issues.
Comment 1 Klaus Kämpf 2010-06-29 08:32:34 UTC
The problem is that you cannot create TreeItems stand-alone. They need to be embedded into a dialog and a vbox/hbox:


factory = yui.YUI.widgetFactory()
dialog = factory.createPopupDialog()

vbox = factory.createVBox( dialog )

item = factory.createTree(vbox, "root")

event = dialog.waitForEvent()
dialog.destroy()


This examples runs without crash. My knowledge about libyui trees is too limited to complete the example :-(

Bubli, any hints how to properly add items to the tree ?
Comment 2 Katarina Machalkova 2010-06-29 08:46:31 UTC
The following code creates a tree with 2 items (top- and 1st level)

factory = yui.YUI.widgetFactory()
dialog = factory.createPopupDialog()

item1 = yui.YTreeItem("hello")
item2 = yui.YTreeItem( item1, "world")

vbox = factory.createVBox( dialog )
tree = factory.createTree( vbox, "Hello, World!" )
// add top level item only, its children will be added automatically
tree.addItem(item1)

factory.createPushButton( vbox, "&OK" )
event = dialog.waitForEvent()
dialog.destroy()

For some reason, the tree items are visible only in ncurses (GUI shows an empty box). Nevertheless, segfault on dialog close occurs in both cases
Comment 3 Katarina Machalkova 2010-06-29 09:43:55 UTC
Hm, tried to obtain some backtrace, but this is all I managed to get :( 

#0  0x00000031 in ?? ()
#1  0xc381fffd in ?? ()
Backtrace stopped: previous frame inner to this frame (corrupt stack?)
Comment 4 Klaus Kämpf 2010-06-29 10:55:56 UTC
See https://bugzilla.novell.com/show_bug.cgi?id=427372#c16

Its a double-free.

The addItem call transfers the 'memory ownership' to 'tree' but swig thinks it still needs to de-allocated the created item.

This probably needs fixing in libyui
Comment 5 Klaus Kämpf 2010-06-29 11:13:46 UTC
Uhm, no, fixing in libyui (adding _disown to function declarations) doesn't help :-(
Comment 6 Klaus Kämpf 2010-06-29 11:25:31 UTC
I fear the problem is the usage of the YTreeItem constructor.

When using it with a parent, "The parent assumes ownership of this item" (citation from YTreeItem.h).
Comment 7 Klaus Kämpf 2010-06-29 11:39:47 UTC
I was wrong in comment #5. Adding the _disown does the trick but must be done with the correct parameter name.

This fixes the crash:

--- YTreeItem.h (revision 62165)
+++ YTreeItem.h (working copy)
@@ -117,7 +117,7 @@
      * automatically add themselves to their parent, so applications will
      * normally not have to call this function.
      **/
-    virtual void addChild( YItem * child );
+    virtual void addChild( YItem * item_disown );
Comment 8 Klaus Kämpf 2010-06-29 11:41:07 UTC
Committed to svn as rev 62170
Comment 9 Klaus Kämpf 2010-06-29 11:43:11 UTC
Note that this only prevents the crash. It does not fix Qt to properly display the tree. The example works fine in Ncurses though.
Comment 10 Klaus Kämpf 2010-06-29 11:44:06 UTC
Want to push an update out ? ;-)
Comment 11 Katarina Machalkova 2010-06-29 14:42:57 UTC
For 11.3/Factory - sure
For SLE11[-SP1] - we'd have to ask maintenance team for approval then
Comment 12 Klaus Kämpf 2010-06-29 15:41:31 UTC
python-yui is on the SLE11 SDK and thus not maintained.

Closed as fixed for 11.3