Skip to content

Commit b4da602

Browse files
chgnrdvvstinner
authored andcommitted
pythongh-109795: _thread.start_new_thread: allocate thread bootstate using raw memory allocator (python#109808)
(cherry picked from commit 1b8f236)
1 parent 9806f2e commit b4da602

File tree

1 file changed

+6
-3
lines changed

1 file changed

+6
-3
lines changed

Modules/_threadmodule.c

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1078,7 +1078,7 @@ thread_bootstate_free(struct bootstate *boot, int decref)
10781078
Py_DECREF(boot->args);
10791079
Py_XDECREF(boot->kwargs);
10801080
}
1081-
PyMem_Free(boot);
1081+
PyMem_RawFree(boot);
10821082
}
10831083

10841084

@@ -1196,13 +1196,16 @@ thread_PyThread_start_new_thread(PyObject *self, PyObject *fargs)
11961196
return NULL;
11971197
}
11981198

1199-
struct bootstate *boot = PyMem_NEW(struct bootstate, 1);
1199+
// gh-109795: Use PyMem_RawMalloc() instead of PyMem_Malloc(),
1200+
// because it should be possible to call thread_bootstate_free()
1201+
// without holding the GIL.
1202+
struct bootstate *boot = PyMem_RawMalloc(sizeof(struct bootstate));
12001203
if (boot == NULL) {
12011204
return PyErr_NoMemory();
12021205
}
12031206
boot->tstate = _PyThreadState_New(interp);
12041207
if (boot->tstate == NULL) {
1205-
PyMem_Free(boot);
1208+
PyMem_RawFree(boot);
12061209
if (!PyErr_Occurred()) {
12071210
return PyErr_NoMemory();
12081211
}

0 commit comments

Comments
 (0)