gh-128679: Fix tracemalloc.stop() race conditions#128893
gh-128679: Fix tracemalloc.stop() race conditions#128893vstinner merged 1 commit intopython:mainfrom
Conversation
tracemalloc_alloc(), tracemalloc_realloc(), tracemalloc_free(), _PyTraceMalloc_TraceRef() and _PyTraceMalloc_GetMemory() now check tracemalloc_config.tracing after calling TABLES_LOCK(). _PyTraceMalloc_TraceRef() now always returns 0.
|
@ZeroIntensity: Ok, here is the new fix for #128679 tracemalloc.stop() race condition. Thanks to #128888 refactoring, the fix is simpler and should be more reliable than my previous attempt. Moreover, this fix is more complete: I fixed more functions. |
|
For the test, I prefer to use |
|
Ok, that makes sense. We might want to expose that publicly at some point, FWIW. |
|
To be perfectly clear--what are the rules for |
It's protected by TABLES_LOCK(). Basically, the whole tracemalloc state is protected by TABLES_LOCK(). The GIL is needed on memory allocations to get the traceback. It's not needed on deallocations. |
|
Merged. Thanks for your reviews @ZeroIntensity! |
tracemalloc_alloc(), tracemalloc_realloc(), tracemalloc_free(), _PyTraceMalloc_TraceRef() and _PyTraceMalloc_GetMemory() now check tracemalloc_config.tracing after calling TABLES_LOCK().
_PyTraceMalloc_TraceRef() now always returns 0.