diff --git a/qrenderdoc/Code/pyrenderdoc/PythonContext.cpp b/qrenderdoc/Code/pyrenderdoc/PythonContext.cpp index dc83f1971..26de3b7fb 100644 --- a/qrenderdoc/Code/pyrenderdoc/PythonContext.cpp +++ b/qrenderdoc/Code/pyrenderdoc/PythonContext.cpp @@ -225,11 +225,14 @@ void FetchException(QString &typeStr, QString &valueStr, int &finalLine, QListdeleteLater(); - }); - } - }; - } + invokeObj->deleteLater(); + }); + } + }; } } #endif @@ -990,6 +987,8 @@ except: qCritical() << "Couldn't find valid stubs path"; } + Py_XDECREF(sysobj); + m_DeferredInit = 1; PyGILState_Release(gil); @@ -1033,7 +1032,7 @@ PythonContext::PythonContext(bool extensionContext, QObject *parent) : QObject(p output->context = this; output->selfDeleting = !extensionContext; output->block = false; - Py_DECREF(redirector); + Py_XDECREF(redirector); } // release the GIL again @@ -1089,7 +1088,7 @@ bool PythonContext::CheckInterfaces(rdcstr &log) } } - Py_DECREF(mod); + Py_XDECREF(mod); } PyGILState_Release(gil); @@ -1237,6 +1236,7 @@ QString PythonContext::LoadExtension(ICaptureContext &ctx, const rdcstr &extensi // discard the return value, regardless of error we don't abort the reload Py_XDECREF(retval); + Py_XDECREF(unregister_func); } if(reloadSuccess) @@ -1276,7 +1276,7 @@ QString PythonContext::LoadExtension(ICaptureContext &ctx, const rdcstr &extensi } // we don't need the reference, we just wanted to reload it - Py_DECREF(mod); + Py_XDECREF(mod); value = PyDict_GetItem(sysmodules, key); @@ -1286,8 +1286,10 @@ QString PythonContext::LoadExtension(ICaptureContext &ctx, const rdcstr &extensi } } - Py_DECREF(keys); + Py_XDECREF(keys); } + + Py_XDECREF(sysmodules); } if(reloadSuccess) @@ -1339,6 +1341,8 @@ QString PythonContext::LoadExtension(ICaptureContext &ctx, const rdcstr &extensi ret += tr("Internal error passing pyrenderdoc to extension register()\n"); } + Py_XDECREF(register_func); + if(retval == NULL) { qCritical() << "register() function failed"; @@ -1826,13 +1830,14 @@ QString PythonContext::typenameForLoc(int line, int col) { ret = ToQStr(name); - Py_XDECREF(typeObj); Py_XDECREF(name); } else { HandleException(NULL); } + + Py_XDECREF(typeObj); } PyGILState_Release(gil); @@ -1945,12 +1950,7 @@ void PythonContext::AddDebuggableThread() if(!threadName.isEmpty()) { - PyObject *sys = PyImport_ImportModule("sys"); - Q_ASSERT(sys); - PyObject *modules = PyObject_SafeGetAttrString(sys, "modules"); - Q_ASSERT(modules); - - PyObject *threading = PyDict_GetItemString(modules, "threading"); + PyObject *threading = PyImport_ImportModule("threading"); // expect to load threading if(threading) @@ -1971,9 +1971,12 @@ void PythonContext::AddDebuggableThread() Py_XDECREF(current_thread); } + else + { + qCritical() << "Couldn't get threading module"; + } - Py_XDECREF(modules); - Py_XDECREF(sys); + Py_XDECREF(threading); } PyGILState_Release(gil); @@ -1988,12 +1991,7 @@ void PythonContext::RemoveDebuggableThread() #if PY_MAJOR_VERSION == 3 && PY_MINOR_VERSION < 13 PyGILState_STATE gil = PyGILState_Ensure(); - PyObject *sys = PyImport_ImportModule("sys"); - Q_ASSERT(sys); - PyObject *modules = PyObject_SafeGetAttrString(sys, "modules"); - Q_ASSERT(modules); - - PyObject *threading = PyDict_GetItemString(modules, "threading"); + PyObject *threading = PyImport_ImportModule("threading"); // expect to load threading if(threading) @@ -2010,6 +2008,12 @@ void PythonContext::RemoveDebuggableThread() Py_XDECREF(_active); } + else + { + qCritical() << "Couldn't get threading module"; + } + + Py_XDECREF(threading); PyGILState_Release(gil); #endif