Repository navigation
test_intern in test_sys leaks negative references in free-threaded build #122420
Copy link
Copy link
Closed
Labels
3.13only security fixesonly security fixes3.14bugs and security fixesbugs and security fixestopic-free-threadingtype-bugAn unexpected behavior, bug, or errorAn unexpected behavior, bug, or error
Description
Activity
- addedtype-bugAn unexpected behavior, bug, or errorAn unexpected behavior, bug, or error3.13only security fixesonly security fixes3.14bugs and security fixesbugs and security fixes
on Jul 29, 2024 cc @encukou
I think this is just an issue with
refleak.py:cpython/Lib/test/libregrtest/refleak.py
Lines 144 to 148 in 046670c
interned_immortal_after = getunicodeinternedsize( # Use an internal-only keyword argument that mypy doesn't know yet _only_immortal=True) # type: ignore[call-arg] alloc_after = getallocatedblocks() - interned_immortal_after rc_after = gettotalrefcount() - interned_immortal_after * 2 We now account for those two references in
intern_common, so we shouldn't subtract them out inrefleak.py:cpython/Objects/unicodeobject.c
Lines 15518 to 15527 in 046670c
if (!_Py_IsImmortal(s)) { /* The two references in interned dict (key and value) are not counted. unicode_dealloc() and _PyUnicode_ClearInterned() take care of this. */ Py_SET_REFCNT(s, Py_REFCNT(s) - 2); #ifdef Py_REF_DEBUG /* let's be pedantic with the ref total */ _Py_DecRefTotal(_PyThreadState_GET()); _Py_DecRefTotal(_PyThreadState_GET()); #endif } - added a commit that references this issue
on Jul 29, 2024 - added a commit that references this issue
on Jul 30, 2024
Metadata
Metadata
Assignees
Labels
3.13only security fixesonly security fixes3.14bugs and security fixesbugs and security fixestopic-free-threadingtype-bugAn unexpected behavior, bug, or errorAn unexpected behavior, bug, or error
Bug report
The
test_interntest "leaks" -2 references in the free-threaded build. This isn't caught by the refleak build bots because negative refleaks are treated as "suspicious" rather than "failing". This is a problem because the negative "leak" can hide a real leak somewhere else.I think there's likely something wrong with the accounting for references in the
immortalize=1case inintern_commonbecause this shows up in the free-threaded build, but not the default build.Linked PRs