Mercurial > cpython-lru_cache-weakref
comparison Python/pystate.c @ 84419:ebe064e542ef
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.
| author | Christian Heimes <christian@cheimes.de> |
|---|---|
| date | Mon, 01 Jul 2013 23:43:09 +0200 |
| parents | 375d4fed4cf2 ff30bf84b378 |
| children | 18bb92b0c458 |
comparison
equal
deleted
inserted
replaced
| 84417:de44cd866bb0 | 84419:ebe064e542ef |
|---|---|
| 372 void | 372 void |
| 373 PyThreadState_Delete(PyThreadState *tstate) | 373 PyThreadState_Delete(PyThreadState *tstate) |
| 374 { | 374 { |
| 375 if (tstate == _Py_atomic_load_relaxed(&_PyThreadState_Current)) | 375 if (tstate == _Py_atomic_load_relaxed(&_PyThreadState_Current)) |
| 376 Py_FatalError("PyThreadState_Delete: tstate is still current"); | 376 Py_FatalError("PyThreadState_Delete: tstate is still current"); |
| 377 tstate_delete_common(tstate); | |
| 378 #ifdef WITH_THREAD | 377 #ifdef WITH_THREAD |
| 379 if (autoInterpreterState && PyThread_get_key_value(autoTLSkey) == tstate) | 378 if (autoInterpreterState && PyThread_get_key_value(autoTLSkey) == tstate) |
| 380 PyThread_delete_key_value(autoTLSkey); | 379 PyThread_delete_key_value(autoTLSkey); |
| 381 #endif /* WITH_THREAD */ | 380 #endif /* WITH_THREAD */ |
| 381 tstate_delete_common(tstate); | |
| 382 } | 382 } |
| 383 | 383 |
| 384 | 384 |
| 385 #ifdef WITH_THREAD | 385 #ifdef WITH_THREAD |
| 386 void | 386 void |
| 390 &_PyThreadState_Current); | 390 &_PyThreadState_Current); |
| 391 if (tstate == NULL) | 391 if (tstate == NULL) |
| 392 Py_FatalError( | 392 Py_FatalError( |
| 393 "PyThreadState_DeleteCurrent: no current tstate"); | 393 "PyThreadState_DeleteCurrent: no current tstate"); |
| 394 _Py_atomic_store_relaxed(&_PyThreadState_Current, NULL); | 394 _Py_atomic_store_relaxed(&_PyThreadState_Current, NULL); |
| 395 tstate_delete_common(tstate); | |
| 396 if (autoInterpreterState && PyThread_get_key_value(autoTLSkey) == tstate) | 395 if (autoInterpreterState && PyThread_get_key_value(autoTLSkey) == tstate) |
| 397 PyThread_delete_key_value(autoTLSkey); | 396 PyThread_delete_key_value(autoTLSkey); |
| 397 tstate_delete_common(tstate); | |
| 398 PyEval_ReleaseLock(); | 398 PyEval_ReleaseLock(); |
| 399 } | 399 } |
| 400 #endif /* WITH_THREAD */ | 400 #endif /* WITH_THREAD */ |
| 401 | 401 |
| 402 | 402 |
