Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit b9dbc7d

Browse files
committed
Issue #18328: Reorder ops in PyThreadState_Delete*() functions. Now the
tstate is first removed from TLS and then deallocated. CID 1019639 (#1 of 1): Use after free (USE_AFTER_FREE) use_after_free: Using freed pointer tstate.
1 parent 2178248 commit b9dbc7d

2 files changed

Lines changed: 5 additions & 2 deletions

File tree

Misc/NEWS

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,9 @@ What's New in Python 3.3.3 release candidate 1?
1212
Core and Builtins
1313
-----------------
1414

15+
- Issue #18328: Reorder ops in PyThreadState_Delete*() functions. Now the
16+
tstate is first removed from TLS and then deallocated.
17+
1518
- Issue #18184: PyUnicode_FromFormat() and PyUnicode_FromFormatV() now raise
1619
OverflowError when an argument of %c format is out of range.
1720

Python/pystate.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -388,11 +388,11 @@ PyThreadState_Delete(PyThreadState *tstate)
388388
{
389389
if (tstate == _Py_atomic_load_relaxed(&_PyThreadState_Current))
390390
Py_FatalError("PyThreadState_Delete: tstate is still current");
391-
tstate_delete_common(tstate);
392391
#ifdef WITH_THREAD
393392
if (autoInterpreterState && PyThread_get_key_value(autoTLSkey) == tstate)
394393
PyThread_delete_key_value(autoTLSkey);
395394
#endif /* WITH_THREAD */
395+
tstate_delete_common(tstate);
396396
}
397397

398398

@@ -406,9 +406,9 @@ PyThreadState_DeleteCurrent()
406406
Py_FatalError(
407407
"PyThreadState_DeleteCurrent: no current tstate");
408408
_Py_atomic_store_relaxed(&_PyThreadState_Current, NULL);
409-
tstate_delete_common(tstate);
410409
if (autoInterpreterState && PyThread_get_key_value(autoTLSkey) == tstate)
411410
PyThread_delete_key_value(autoTLSkey);
411+
tstate_delete_common(tstate);
412412
PyEval_ReleaseLock();
413413
}
414414
#endif /* WITH_THREAD */

0 commit comments

Comments
 (0)