Skip to content

Commit 0afae89

Browse files
vstinnerchgnrdv
andauthored
[3.11] gh-109795: _thread.start_new_thread: allocate thread bootstate usin… (#109852)
gh-109795: `_thread.start_new_thread`: allocate thread bootstate using raw memory allocator (#109808) (cherry picked from commit 1b8f236) Co-authored-by: Radislav Chugunov <[email protected]>
1 parent 9238c68 commit 0afae89

File tree

1 file changed

+6
-3
lines changed

1 file changed

+6
-3
lines changed

Modules/_threadmodule.c

+6-3
Original file line numberDiff line numberDiff line change
@@ -1068,7 +1068,7 @@ thread_bootstate_free(struct bootstate *boot, int decref)
10681068
Py_DECREF(boot->args);
10691069
Py_XDECREF(boot->kwargs);
10701070
}
1071-
PyMem_Free(boot);
1071+
PyMem_RawFree(boot);
10721072
}
10731073

10741074

@@ -1164,13 +1164,16 @@ thread_PyThread_start_new_thread(PyObject *self, PyObject *fargs)
11641164
return NULL;
11651165
}
11661166

1167-
struct bootstate *boot = PyMem_NEW(struct bootstate, 1);
1167+
// gh-109795: Use PyMem_RawMalloc() instead of PyMem_Malloc(),
1168+
// because it should be possible to call thread_bootstate_free()
1169+
// without holding the GIL.
1170+
struct bootstate *boot = PyMem_RawMalloc(sizeof(struct bootstate));
11681171
if (boot == NULL) {
11691172
return PyErr_NoMemory();
11701173
}
11711174
boot->tstate = _PyThreadState_Prealloc(interp);
11721175
if (boot->tstate == NULL) {
1173-
PyMem_Free(boot);
1176+
PyMem_RawFree(boot);
11741177
return PyErr_NoMemory();
11751178
}
11761179
boot->func = Py_NewRef(func);

0 commit comments

Comments
 (0)