GeezerVison is showing github.com — [3.11] gh-109795: `_thread.start_new_thread`: allocate thread bootsta… · python/cpython@0afae89
File tree
Expand file treeCollapse file tree
Open diff view settings
Expand file treeCollapse file tree
Open diff view settings
Collapse file
Copy file name to clipboardExpand all lines: Modules/_threadmodule.c +6-3Lines changed: 6 additions & 3 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -1068,7 +1068,7 @@ thread_bootstate_free(struct bootstate *boot, int decref) |
1068 | 1068 | Py_DECREF(boot->args); |
1069 | 1069 | Py_XDECREF(boot->kwargs); |
1070 | 1070 | } |
1071 | | - PyMem_Free(boot); |
| 1071 | + PyMem_RawFree(boot); |
1072 | 1072 | } |
1073 | 1073 |
|
1074 | 1074 |
|
@@ -1164,13 +1164,16 @@ thread_PyThread_start_new_thread(PyObject *self, PyObject *fargs) |
1164 | 1164 | return NULL; |
1165 | 1165 | } |
1166 | 1166 |
|
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)); |
1168 | 1171 | if (boot == NULL) { |
1169 | 1172 | return PyErr_NoMemory(); |
1170 | 1173 | } |
1171 | 1174 | boot->tstate = _PyThreadState_Prealloc(interp); |
1172 | 1175 | if (boot->tstate == NULL) { |
1173 | | - PyMem_Free(boot); |
| 1176 | + PyMem_RawFree(boot); |
1174 | 1177 | return PyErr_NoMemory(); |
1175 | 1178 | } |
1176 | 1179 | boot->func = Py_NewRef(func); |
|