Skip to content

Commit 331ad3b

Browse files
jcfrmrbean-bremen
authored andcommitted
fix(cleanup): clear global enum-wrapper registry before tearing down class infos
ASan reported a heap-use-after-free during teardown: the global registry of top-level enum wrappers held raw pointers to `PythonQtClassInfo` that were deleted in `~PythonQtPrivate()`. Subsequent lookups (e.g., triggered by late attribute access) read freed memory. - Add `PythonQtClassInfo::clearGlobalNamespaceWrappers()` - Call it in `~PythonQtPrivate()` before `qDeleteAll(_knownClassInfos)` - Explicitly clear `_knownClassInfos` after deletion to avoid stale entries
1 parent fa3f76a commit 331ad3b

File tree

3 files changed

+13
-3
lines changed

3 files changed

+13
-3
lines changed

src/PythonQt.cpp

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -421,9 +421,10 @@ PythonQtPrivate::~PythonQtPrivate() {
421421
delete _defaultImporter;
422422
_defaultImporter = nullptr;
423423

424-
{
425-
qDeleteAll(_knownClassInfos);
426-
}
424+
PythonQtClassInfo::clearGlobalNamespaceWrappers();
425+
426+
qDeleteAll(_knownClassInfos);
427+
_knownClassInfos.clear();
427428

428429
PythonQtMethodInfo::cleanupCachedMethodInfos();
429430
PythonQtArgumentFrame::cleanupFreeList();

src/PythonQtClassInfo.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1043,6 +1043,11 @@ void PythonQtClassInfo::addGlobalNamespaceWrapper(PythonQtClassInfo* namespaceWr
10431043
_globalNamespaceWrappers.insert(0, namespaceWrapper);
10441044
}
10451045

1046+
void PythonQtClassInfo::clearGlobalNamespaceWrappers()
1047+
{
1048+
_globalNamespaceWrappers.clear();
1049+
}
1050+
10461051
void PythonQtClassInfo::updateRefCountingCBs()
10471052
{
10481053
if (!_refCallback) {

src/PythonQtClassInfo.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -244,6 +244,10 @@ class PYTHONQT_EXPORT PythonQtClassInfo {
244244
//! Add a wrapper that contains global enums
245245
static void addGlobalNamespaceWrapper(PythonQtClassInfo* namespaceWrapper);
246246

247+
//! Clear the registry of global-namespace wrappers (used for top-level enums).
248+
//! Must be called before destroying PythonQtClassInfo instances and before a fresh init.
249+
static void clearGlobalNamespaceWrappers();
250+
247251
private:
248252
void updateRefCountingCBs();
249253

0 commit comments

Comments
 (0)