summaryrefslogtreecommitdiffstats
path: root/Modules
diff options
context:
space:
mode:
authorRadislav Chugunov <52372310+chgnrdv@users.noreply.github.com>2023-09-25 15:38:06 (GMT)
committerGitHub <noreply@github.com>2023-09-25 15:38:06 (GMT)
commit1b8f2366b38c87b0450d9c15bdfdd4c4a2fc3a01 (patch)
tree66c9f8352997ce63ed77c86e669bbf929265d014 /Modules
parentf19416534a546460fdf6a0739b70e44d1950a073 (diff)
downloadcpython-1b8f2366b38c87b0450d9c15bdfdd4c4a2fc3a01.zip
cpython-1b8f2366b38c87b0450d9c15bdfdd4c4a2fc3a01.tar.gz
cpython-1b8f2366b38c87b0450d9c15bdfdd4c4a2fc3a01.tar.bz2
gh-109795: `_thread.start_new_thread`: allocate thread bootstate using raw memory allocator (#109808)
Diffstat (limited to 'Modules')
-rw-r--r--Modules/_threadmodule.c9
1 files changed, 6 insertions, 3 deletions
diff --git a/Modules/_threadmodule.c b/Modules/_threadmodule.c
index 9c91548..fa98df5 100644
--- a/Modules/_threadmodule.c
+++ b/Modules/_threadmodule.c
@@ -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);
}
@@ -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();
}