Uploaded image for project: 'Qt for Python'
  1. Qt for Python
  2. PYSIDE-264

app crash after deleting C++-created objects



    • Type: Bug
    • Status: Closed
    • Priority: P2: Important
    • Resolution: Done
    • Affects Version/s: 1.2.2, dev
    • Fix Version/s: 5.9
    • Component/s: PySide
    • Labels:
    • Environment:
      Tested on Windows 7, Python 3.4, PySide 1.2.2 and on Ubuntu 12.04 with Python 3.4, Qt 4.8 and PySide 1.2.2.
    • Commits:


      Example of crashing code is in attachment.

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


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


      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.


      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.


        1. crash_example.py
          1 kB
          Andrey Golynskiy
        2. pyside-264-crash_example.py
          1 kB
          Christian Tismer
        For Gerrit Dashboard: PYSIDE-264
        # Subject Branch Project Status CR V



            • Assignee:
              crmaurei Cristian Maureira-Fredes
              veon Andrey Golynskiy
            • Votes:
              1 Vote for this issue
              4 Start watching this issue


              • Created:

                Gerrit Reviews

                There are no open Gerrit changes