]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
gh-109795: `_thread.start_new_thread`: allocate thread bootstate using raw memory...
authorRadislav Chugunov <52372310+chgnrdv@users.noreply.github.com>
Mon, 25 Sep 2023 15:38:06 +0000 (18:38 +0300)
committerGitHub <noreply@github.com>
Mon, 25 Sep 2023 15:38:06 +0000 (17:38 +0200)
Modules/_threadmodule.c

index 9c915488f6e0de3048b9600a55a8248b6ab27d41..fa98df516b8b1027ba046d6636f9252098c47dfb 100644 (file)
@@ -1066,7 +1066,7 @@ thread_bootstate_free(struct bootstate *boot, int decref)
         Py_DECREF(boot->args);
         Py_XDECREF(boot->kwargs);
     }
-    PyMem_Free(boot);
+    PyMem_RawFree(boot);
 }
 
 
@@ -1184,13 +1184,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_New(interp);
     if (boot->tstate == NULL) {
-        PyMem_Free(boot);
+        PyMem_RawFree(boot);
         if (!PyErr_Occurred()) {
             return PyErr_NoMemory();
         }