Skip to content

Commit bfc5b5c

Browse files
committed
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 2d59af7 commit bfc5b5c

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
@@ -418,9 +418,10 @@ PythonQtPrivate::~PythonQtPrivate() {
418418
delete _defaultImporter;
419419
_defaultImporter = nullptr;
420420

421-
{
422-
qDeleteAll(_knownClassInfos);
423-
}
421+
PythonQtClassInfo::clearGlobalNamespaceWrappers();
422+
423+
qDeleteAll(_knownClassInfos);
424+
_knownClassInfos.clear();
424425

425426
PythonQtMethodInfo::cleanupCachedMethodInfos();
426427
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)