Skip to content

Commit 1b8f236

Browse files
authored
gh-109795: _thread.start_new_thread: allocate thread bootstate using raw memory allocator (#109808)
1 parent f194165 commit 1b8f236

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
@@ -1066,7 +1066,7 @@ thread_bootstate_free(struct bootstate *boot, int decref)
10661066
Py_DECREF(boot->args);
10671067
Py_XDECREF(boot->kwargs);
10681068
}
1069-
PyMem_Free(boot);
1069+
PyMem_RawFree(boot);
10701070
}
10711071

10721072

@@ -1184,13 +1184,16 @@ thread_PyThread_start_new_thread(PyObject *self, PyObject *fargs)
11841184
return NULL;
11851185
}
11861186

1187-
struct bootstate *boot = PyMem_NEW(struct bootstate, 1);
1187+
// gh-109795: Use PyMem_RawMalloc() instead of PyMem_Malloc(),
1188+
// because it should be possible to call thread_bootstate_free()
1189+
// without holding the GIL.
1190+
struct bootstate *boot = PyMem_RawMalloc(sizeof(struct bootstate));
11881191
if (boot == NULL) {
11891192
return PyErr_NoMemory();
11901193
}
11911194
boot->tstate = _PyThreadState_New(interp);
11921195
if (boot->tstate == NULL) {
1193-
PyMem_Free(boot);
1196+
PyMem_RawFree(boot);
11941197
if (!PyErr_Occurred()) {
11951198
return PyErr_NoMemory();
11961199
}

0 commit comments

Comments
 (0)