Skip to content

Commit a85a298

Browse files
committed
add requested comment
1 parent 170cf14 commit a85a298

File tree

1 file changed

+7
-0
lines changed

1 file changed

+7
-0
lines changed

Python/tracemalloc.c

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -538,6 +538,13 @@ tracemalloc_alloc(int use_calloc, void *ctx, size_t nelem, size_t elsize)
538538
return NULL;
539539

540540
TABLES_LOCK();
541+
/* This operation can be executed outside of GIL protection due to
542+
allocations needed for an initial PyGILState_Ensure(). Because of this,
543+
tracing may be turned off concurrently in another thread which currently
544+
holds the GIL between the initial check of `tracing` variable and here.
545+
This is a sanity check to account for this possibility and avoid a
546+
potential abort where it can be handled gracefully instead.
547+
See gh-128679. */
541548
if (tracemalloc_config.tracing) {
542549
if (ADD_TRACE(ptr, nelem * elsize) < 0) {
543550
/* Failed to allocate a trace for the new memory block */

0 commit comments

Comments
 (0)