Skip to content

Commit

Permalink
gh-128679: Skip test_tracemalloc_track_race() on debug build (#128988)
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
vstinner authored Jan 18, 2025
1 parent 81159fc commit 9bc1964
Showing 1 changed file with 2 additions and 0 deletions.
2 changes: 2 additions & 0 deletions Lib/test/test_tracemalloc.py
Original file line number Diff line number Diff line change
Expand Up @@ -1103,6 +1103,8 @@ def test_stop_untrack(self):

@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()
Expand Down

0 comments on commit 9bc1964

Please sign in to comment.