[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 1b8f2366b3)

Co-authored-by: Radislav Chugunov <52372310+chgnrdv@users.noreply.github.com>
This commit is contained in:
Victor Stinner 2023-09-25 18:12:43 +02:00 committed by GitHub
parent 9238c6880e
commit 0afae8928b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 6 additions and 3 deletions

View File

@ -1068,7 +1068,7 @@ thread_bootstate_free(struct bootstate *boot, int decref)
Py_DECREF(boot->args);
Py_XDECREF(boot->kwargs);
}
PyMem_Free(boot);
PyMem_RawFree(boot);
}
@ -1164,13 +1164,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_Prealloc(interp);
if (boot->tstate == NULL) {
PyMem_Free(boot);
PyMem_RawFree(boot);
return PyErr_NoMemory();
}
boot->func = Py_NewRef(func);