pyside / PySide

ATTENTION: This project is deprecated, please refer to PySide2
https://wiki.qt.io/PySide2
GNU Lesser General Public License v2.1
291 stars 66 forks source link

app crash after deleting C++-created objects #123

Closed happy-monk closed 9 years ago

happy-monk commented 9 years ago

Example of crash: https://gist.github.com/anonymous/6bec6e87acb62ee81646

Here's explanation of the issue as far as I could understand:

self.view.addItem('AAA')

Method addItem creates instance of QListWidgetItem. It's plain C++ object without any Python wrapper.

self.view.item(0)

Method QListWidget.item creates Python wrapper for created object and links it to the list using function Shiboken::Object::setParent, so the wrapper remains live till the exit from application potentially.

self.view.clear()

QListWidget.clear() clears internal list and destroys every item in it. After this the item object does no more exist, but the corresponding Python wrapper still does and it isn't marked as pointing to invalid object.

So there is two main ways how we can crash program using this invalid wrapper. The first is pretty obvious: try to call any method of previously acquired wrapper. Like in method crash1 from example.

The second way is more vague, and I don't understand the mechanism behind that, but it is more likely to occur and more dangerous. The crash occurs when you instantiate any descendant of QWidget class. It can be absolutely unrelated to the use of item() method so it's very hard to diagnose.

happy-monk commented 9 years ago

Reposted to PySide issue tracker: https://bugreports.qt-project.org/browse/PYSIDE-264