aboutsummaryrefslogtreecommitdiffstats
path: root/sources/pyside6/libpyside/pysideproperty.cpp
diff options
context:
space:
mode:
authorChristian Tismer <tismer@stackless.com>2023-02-14 14:46:22 +0100
committerChristian Tismer <tismer@stackless.com>2023-02-20 09:00:08 +0100
commita754c9f95876de46388387a9eb128c2423f29dd4 (patch)
tree134a32ca4b75ec31299c3b4643132e805e4acbd9 /sources/pyside6/libpyside/pysideproperty.cpp
parentedfd9a5ad174a48f8d7da511dc6a1c69e931a418 (diff)
property: fix an old refcount bug, concluding debug errors
There was a refcounting bug in pysideproperty.cpp that took some time to be understood. By using Property.__init__ multiple times, an omission became manifest: Not clearing a Property instance's attribute before generates a leak. This was the last unsolved reference bug in debug mode :-) Change-Id: Ie91fa9e56ef52ca555168841c99c14fd550202ed Fixes: PYSIDE-1402 Pick-to: 6.4 Reviewed-by: Friedemann Kleint <Friedemann.Kleint@qt.io>
Diffstat (limited to 'sources/pyside6/libpyside/pysideproperty.cpp')
-rw-r--r--sources/pyside6/libpyside/pysideproperty.cpp15
1 files changed, 11 insertions, 4 deletions
diff --git a/sources/pyside6/libpyside/pysideproperty.cpp b/sources/pyside6/libpyside/pysideproperty.cpp
index 1961f566e..4bc5f5b16 100644
--- a/sources/pyside6/libpyside/pysideproperty.cpp
+++ b/sources/pyside6/libpyside/pysideproperty.cpp
@@ -181,7 +181,7 @@ static PyObject *qpropertyTpNew(PyTypeObject *subtype, PyObject * /* args */, Py
static int qpropertyTpInit(PyObject *self, PyObject *args, PyObject *kwds)
{
- PyObject *type = nullptr;
+ PyObject *type{};
auto data = reinterpret_cast<PySideProperty *>(self);
PySidePropertyPrivate *pData = data->d;
@@ -190,6 +190,13 @@ static int qpropertyTpInit(PyObject *self, PyObject *args, PyObject *kwds)
"user", "constant", "final", nullptr};
char *doc{};
+ Py_CLEAR(pData->pyTypeObject);
+ Py_CLEAR(pData->fget);
+ Py_CLEAR(pData->fset);
+ Py_CLEAR(pData->freset);
+ Py_CLEAR(pData->fdel);
+ Py_CLEAR(pData->notify);
+
if (!PyArg_ParseTupleAndKeywords(args, kwds,
"O|OOOOsObbbbbb:QtCore.Property",
const_cast<char **>(kwlist),
@@ -409,6 +416,7 @@ static int qpropertyTraverse(PyObject *self, visitproc visit, void *arg)
Py_VISIT(data->freset);
Py_VISIT(data->fdel);
Py_VISIT(data->notify);
+ Py_VISIT(data->pyTypeObject);
return 0;
}
@@ -423,7 +431,7 @@ static int qpropertyClear(PyObject *self)
Py_CLEAR(data->freset);
Py_CLEAR(data->fdel);
Py_CLEAR(data->notify);
- Py_XDECREF(data->pyTypeObject);
+ Py_CLEAR(data->pyTypeObject);
delete data;
reinterpret_cast<PySideProperty *>(self)->d = nullptr;
@@ -569,9 +577,8 @@ bool isFinal(const PySideProperty *self)
const char *getNotifyName(PySideProperty *self)
{
if (self->d->notifySignature.isEmpty()) {
- PyObject *str = PyObject_Str(self->d->notify);
+ AutoDecRef str(PyObject_Str(self->d->notify));
self->d->notifySignature = Shiboken::String::toCString(str);
- Py_DECREF(str);
}
return self->d->notifySignature.isEmpty()