Skip to content

Commit

Permalink
gh-109795: _thread.start_new_thread: allocate thread bootstate usin…
Browse files Browse the repository at this point in the history
…g raw memory allocator (#109808)
  • Loading branch information
chgnrdv authored Sep 25, 2023
1 parent f194165 commit 1b8f236
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions Modules/_threadmodule.c
Original file line number Diff line number Diff line change
Expand Up @@ -1066,7 +1066,7 @@ thread_bootstate_free(struct bootstate *boot, int decref)
Py_DECREF(boot->args);
Py_XDECREF(boot->kwargs);
}
PyMem_Free(boot);
PyMem_RawFree(boot);
}


Expand Down Expand Up @@ -1184,13 +1184,16 @@ thread_PyThread_start_new_thread(PyObject *self, PyObject *fargs)
return NULL;
}

struct bootstate *boot = PyMem_NEW(struct bootstate, 1);
// gh-109795: Use PyMem_RawMalloc() instead of PyMem_Malloc(),
// because it should be possible to call thread_bootstate_free()
// without holding the GIL.
struct bootstate *boot = PyMem_RawMalloc(sizeof(struct bootstate));
if (boot == NULL) {
return PyErr_NoMemory();
}
boot->tstate = _PyThreadState_New(interp);
if (boot->tstate == NULL) {
PyMem_Free(boot);
PyMem_RawFree(boot);
if (!PyErr_Occurred()) {
return PyErr_NoMemory();
}
Expand Down

0 comments on commit 1b8f236

Please sign in to comment.