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

Lazy import reference counting bug

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Fixed
    • Icon: P3: Somewhat important P3: Somewhat important
    • 6.7.2, 6.8.0, 6.7.3
    • 6.7.0, 6.7.1
    • PySide
    • None
    • All
    • 68b7fd5c7 (dev), 90b532331 (6.7), e070b79c0 (6.7.2), 285bec6dc (tqtc/6.7.2)

      In sbkmodule.cpp, line 472, the original _import_ function is fetched from the builtins dict without incrementing the reference count.

      If later the _import_ function in the builtins is replaced then the one held here will be destroyed leaving an invalid function object, which will cause a crash on the next import.

      A Py_INCREF should follow PyDict_GetItemString, since that returns a borrowed reference:

       
      static PyObject *origImportFunc{};
      ..
      static PyObject *lazy_import()
      ...
      origImportFunc = PyDict_GetItemString(builtins, "__import__");
      Py_INCREF(origImportFunc)  // This is missing around line 473
       

       
      It looks like this bug was introduced in commit 7accf7c3042e3f0680fa0615a0f13b54d28a0efd "LazyInit: Implement Lazy Initialization by Delayed Module Entries" https://codereview.qt-project.org/c/pyside/pyside-setup/+/539467

        No reviews matched the request. Check your Options in the drop-down menu of this sections header.

            ctismer Christian Tismer
            tonyr Tony Roberts
            Votes:
            0 Vote for this issue
            Watchers:
            5 Start watching this issue

              Created:
              Updated:
              Resolved:

                There are no open Gerrit changes