diff options
author | Pablo Galindo <Pablogsal@gmail.com> | 2018-08-31 21:49:29 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2018-08-31 21:49:29 (GMT) |
commit | 95d630e2213fb0ffc197ec440efa3ae3dbb74f8d (patch) | |
tree | 7395b86f7a1566d9d3d1844b61dcdfce573b9d6f /Python | |
parent | 745c0f3980c56e88db6a57311fb20ea11005565b (diff) | |
download | cpython-95d630e2213fb0ffc197ec440efa3ae3dbb74f8d.zip cpython-95d630e2213fb0ffc197ec440efa3ae3dbb74f8d.tar.gz cpython-95d630e2213fb0ffc197ec440efa3ae3dbb74f8d.tar.bz2 |
bpo-34408: Prevent a null pointer dereference and resource leakage in `PyInterpreterState_New()` (GH-8767)
* A pointer in `PyInterpreterState_New()` could have been `NULL` when being dereferenced.
* Memory was leaked in `PyInterpreterState_New()` when taking some error-handling code path.
Diffstat (limited to 'Python')
-rw-r--r-- | Python/pystate.c | 16 |
1 files changed, 10 insertions, 6 deletions
diff --git a/Python/pystate.c b/Python/pystate.c index 7a4cd48..7d63f4f 100644 --- a/Python/pystate.c +++ b/Python/pystate.c @@ -172,23 +172,27 @@ PyInterpreterState_New(void) interp->pyexitmodule = NULL; HEAD_LOCK(); - interp->next = _PyRuntime.interpreters.head; - if (_PyRuntime.interpreters.main == NULL) { - _PyRuntime.interpreters.main = interp; - } - _PyRuntime.interpreters.head = interp; if (_PyRuntime.interpreters.next_id < 0) { /* overflow or Py_Initialize() not called! */ PyErr_SetString(PyExc_RuntimeError, "failed to get an interpreter ID"); - /* XXX deallocate! */ + PyMem_RawFree(interp); interp = NULL; } else { interp->id = _PyRuntime.interpreters.next_id; _PyRuntime.interpreters.next_id += 1; + interp->next = _PyRuntime.interpreters.head; + if (_PyRuntime.interpreters.main == NULL) { + _PyRuntime.interpreters.main = interp; + } + _PyRuntime.interpreters.head = interp; } HEAD_UNLOCK(); + if (interp == NULL) { + return NULL; + } + interp->tstate_next_unique_id = 0; return interp; |