Skip to content

Commit c69bfa8

Browse files
committed
Move assert() inside lock to avoid data race.
We need to hold the lock to safely read the `tstate->interp->sys_tracing_threads` value.
1 parent ebc24d5 commit c69bfa8

File tree

1 file changed

+1
-1
lines changed

1 file changed

+1
-1
lines changed

Python/legacy_tracing.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -582,10 +582,10 @@ _PyEval_SetTrace(PyThreadState *tstate, Py_tracefunc func, PyObject *arg)
582582
if (_PySys_Audit(current_tstate, "sys.settrace", NULL) < 0) {
583583
return -1;
584584
}
585-
assert(tstate->interp->sys_tracing_threads >= 0);
586585
// needs to be decref'd outside of the lock
587586
PyObject *old_traceobj;
588587
LOCK_SETUP();
588+
assert(tstate->interp->sys_tracing_threads >= 0);
589589
Py_ssize_t tracing_threads = setup_tracing(tstate, func, arg, &old_traceobj);
590590
UNLOCK_SETUP();
591591
Py_XDECREF(old_traceobj);

0 commit comments

Comments
 (0)