Py_DECREF(boot->args);
Py_XDECREF(boot->kwargs);
}
- PyMem_Free(boot);
+ PyMem_RawFree(boot);
}
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_New(interp);
if (boot->tstate == NULL) {
- PyMem_Free(boot);
+ PyMem_RawFree(boot);
if (!PyErr_Occurred()) {
return PyErr_NoMemory();
}