diff options
author | Friedemann Kleint <Friedemann.Kleint@qt.io> | 2024-04-23 14:17:15 +0200 |
---|---|---|
committer | Friedemann Kleint <Friedemann.Kleint@qt.io> | 2024-04-24 10:20:16 +0200 |
commit | f34dcb84adf20e9f3428660636aa8d377d14fc3b (patch) | |
tree | e44f337979c036d2eb41e7e04b358a6b37bc8a56 /sources/shiboken6/libshiboken/basewrapper.cpp | |
parent | c0674262fd7e859a8002e6e850b6ec0a4162b456 (diff) |
shiboken6: Fix leaking tuples in introduceWrapperType()
When calling introduceWrapperType(), the generated
code creates and leaks a tuple of base types if there
are base classes. When there are no base classes, a
tuple (containing SbkObjectType) is created and leaked
within introduceWrapperType().
To fix this, generate the complete tuple including
SbkObjectType in the generated code and remove the
base type parameter to introduceWrapperType().
Pick-to: 6.7
Task-number: PYSIDE-1617
Change-Id: Ib3bec8e6b94bea14a46df826667373d3f859dfd5
Reviewed-by: Cristian Maureira-Fredes <cristian.maureira-fredes@qt.io>
Diffstat (limited to 'sources/shiboken6/libshiboken/basewrapper.cpp')
-rw-r--r-- | sources/shiboken6/libshiboken/basewrapper.cpp | 11 |
1 files changed, 5 insertions, 6 deletions
diff --git a/sources/shiboken6/libshiboken/basewrapper.cpp b/sources/shiboken6/libshiboken/basewrapper.cpp index 35d46b1aa..5c058c482 100644 --- a/sources/shiboken6/libshiboken/basewrapper.cpp +++ b/sources/shiboken6/libshiboken/basewrapper.cpp @@ -970,17 +970,16 @@ introduceWrapperType(PyObject *enclosingObject, const char *originalName, PyType_Spec *typeSpec, ObjectDestructor cppObjDtor, - PyTypeObject *baseType, - PyObject *baseTypes, + PyObject *bases, unsigned wrapperFlags) { - auto *base = baseType ? baseType : SbkObject_TypeF(); - typeSpec->slots[0].pfunc = reinterpret_cast<void *>(base); - auto *bases = baseTypes ? baseTypes : PyTuple_Pack(1, base); + const auto basesSize = PySequence_Fast_GET_SIZE(bases); + assert(basesSize > 0); + typeSpec->slots[0].pfunc = PySequence_Fast_GET_ITEM(bases, 0); auto *type = SbkType_FromSpecBasesMeta(typeSpec, bases, SbkObjectType_TypeF()); - for (int i = 0; i < PySequence_Fast_GET_SIZE(bases); ++i) { + for (Py_ssize_t i = 0; i < basesSize; ++i) { auto *st = reinterpret_cast<PyTypeObject *>(PySequence_Fast_GET_ITEM(bases, i)); BindingManager::instance().addClassInheritance(st, type); } |