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

Skip to content

Commit 1d5b933

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.
2 parents 3126a3d + b9dbc7d commit 1d5b933

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
@@ -10,6 +10,9 @@ What's New in Python 3.4.0 Alpha 1?
1010
Core and Builtins
1111
-----------------
1212

13+
- Issue #18328: Reorder ops in PyThreadState_Delete*() functions. Now the
14+
tstate is first removed from TLS and then deallocated.
15+
1316
- Issue #13483: Use VirtualAlloc in obmalloc on Windows.
1417

1518
- Issue #18184: PyUnicode_FromFormat() and PyUnicode_FromFormatV() now raise

Python/pystate.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -374,11 +374,11 @@ PyThreadState_Delete(PyThreadState *tstate)
374374
{
375375
if (tstate == _Py_atomic_load_relaxed(&_PyThreadState_Current))
376376
Py_FatalError("PyThreadState_Delete: tstate is still current");
377-
tstate_delete_common(tstate);
378377
#ifdef WITH_THREAD
379378
if (autoInterpreterState && PyThread_get_key_value(autoTLSkey) == tstate)
380379
PyThread_delete_key_value(autoTLSkey);
381380
#endif /* WITH_THREAD */
381+
tstate_delete_common(tstate);
382382
}
383383

384384

@@ -392,9 +392,9 @@ PyThreadState_DeleteCurrent()
392392
Py_FatalError(
393393
"PyThreadState_DeleteCurrent: no current tstate");
394394
_Py_atomic_store_relaxed(&_PyThreadState_Current, NULL);
395-
tstate_delete_common(tstate);
396395
if (autoInterpreterState && PyThread_get_key_value(autoTLSkey) == tstate)
397396
PyThread_delete_key_value(autoTLSkey);
397+
tstate_delete_common(tstate);
398398
PyEval_ReleaseLock();
399399
}
400400
#endif /* WITH_THREAD */

0 commit comments

Comments
 (0)