Skip to content

Commit 99d27fe

Browse files
committed
_PyTraceMalloc_Start(): lock before reading tracing
1 parent ef1718b commit 99d27fe

File tree

1 file changed

+5
-3
lines changed

1 file changed

+5
-3
lines changed

Python/tracemalloc.c

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -978,13 +978,14 @@ _PyTraceMalloc_Start(int max_nframe)
978978
void
979979
_PyTraceMalloc_Stop(void)
980980
{
981-
if (!tracemalloc_config.tracing)
982-
return;
983-
984981
// Lock to synchronize with tracemalloc_free() which checks
985982
// 'tracing' while holding the lock.
986983
TABLES_LOCK();
987984

985+
if (!tracemalloc_config.tracing) {
986+
goto done;
987+
}
988+
988989
/* stop tracing Python memory allocations */
989990
tracemalloc_config.tracing = 0;
990991

@@ -1001,6 +1002,7 @@ _PyTraceMalloc_Stop(void)
10011002
raw_free(tracemalloc_traceback);
10021003
tracemalloc_traceback = NULL;
10031004

1005+
done:
10041006
TABLES_UNLOCK();
10051007
}
10061008

0 commit comments

Comments
 (0)