gh-128679: Skip test_tracemalloc_track_race() on debug build (#128988)

There is a race condition between PyMem_SetAllocator() and
PyMem_RawMalloc()/PyMem_RawFree(). While PyMem_SetAllocator() write
is protected by a lock, PyMem_RawMalloc()/PyMem_RawFree() reads are
not protected by a lock. PyMem_RawMalloc()/PyMem_RawFree() can be
called with an old context and the new function pointer.

On a release build, it's not an issue since the context is not used.
On a debug build, the debug hooks use the context and so can crash.
This commit is contained in:
Victor Stinner 2025-01-18 16:13:54 +01:00 committed by GitHub
parent 81159fce36
commit 9bc19643ed
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -1103,6 +1103,8 @@ class TestCAPI(unittest.TestCase):
@unittest.skipIf(_testcapi is None, 'need _testcapi')
@threading_helper.requires_working_threading()
# gh-128679: Test crash on a debug build (especially on FreeBSD).
@unittest.skipIf(support.Py_DEBUG, 'need release build')
def test_tracemalloc_track_race(self):
# gh-128679: Test fix for tracemalloc.stop() race condition
_testcapi.tracemalloc_track_race()