From c27d05a9677afdf04f0b513e14cf0d2a7ec3e4bb Mon Sep 17 00:00:00 2001 From: sobolevn Date: Sun, 28 Jun 2026 13:06:42 +0300 Subject: [PATCH 1/2] gh-151126: Fix a possible crash during the startup with no memory under `Py_STACKREF_DEBUG` --- .../Library/2026-06-28-13-05-52.gh-issue-151126.KE2OvV.rst | 2 ++ Python/pystate.c | 6 ++++++ 2 files changed, 8 insertions(+) create mode 100644 Misc/NEWS.d/next/Library/2026-06-28-13-05-52.gh-issue-151126.KE2OvV.rst diff --git a/Misc/NEWS.d/next/Library/2026-06-28-13-05-52.gh-issue-151126.KE2OvV.rst b/Misc/NEWS.d/next/Library/2026-06-28-13-05-52.gh-issue-151126.KE2OvV.rst new file mode 100644 index 000000000000000..4ee4f96cda5d9be --- /dev/null +++ b/Misc/NEWS.d/next/Library/2026-06-28-13-05-52.gh-issue-151126.KE2OvV.rst @@ -0,0 +1,2 @@ +Fix a possible crash during the interpreter startup under a memory pressure +with ``Py_STACKREF_DEBUG`` enabled. diff --git a/Python/pystate.c b/Python/pystate.c index 29f13e92e0dd1fd..e90642fa882db72 100644 --- a/Python/pystate.c +++ b/Python/pystate.c @@ -656,6 +656,9 @@ init_interpreter(PyInterpreterState *interp, NULL, &alloc ); + if (interp->open_stackrefs_table == NULL) { + return _PyStatus_NO_MEMORY(); + } # ifdef Py_STACKREF_CLOSE_DEBUG interp->closed_stackrefs_table = _Py_hashtable_new_full( _Py_hashtable_hash_ptr, @@ -664,6 +667,9 @@ init_interpreter(PyInterpreterState *interp, NULL, &alloc ); + if (interp->closed_stackrefs_table == NULL) { + return _PyStatus_NO_MEMORY(); + } # endif _Py_stackref_associate(interp, Py_None, PyStackRef_None); _Py_stackref_associate(interp, Py_False, PyStackRef_False); From 1e8edf9b31b248cd83dac62c19699b5efad0a8b9 Mon Sep 17 00:00:00 2001 From: sobolevn Date: Mon, 29 Jun 2026 01:44:16 +0300 Subject: [PATCH 2/2] Delete Misc/NEWS.d/next/Library/2026-06-28-13-05-52.gh-issue-151126.KE2OvV.rst --- .../next/Library/2026-06-28-13-05-52.gh-issue-151126.KE2OvV.rst | 2 -- 1 file changed, 2 deletions(-) delete mode 100644 Misc/NEWS.d/next/Library/2026-06-28-13-05-52.gh-issue-151126.KE2OvV.rst diff --git a/Misc/NEWS.d/next/Library/2026-06-28-13-05-52.gh-issue-151126.KE2OvV.rst b/Misc/NEWS.d/next/Library/2026-06-28-13-05-52.gh-issue-151126.KE2OvV.rst deleted file mode 100644 index 4ee4f96cda5d9be..000000000000000 --- a/Misc/NEWS.d/next/Library/2026-06-28-13-05-52.gh-issue-151126.KE2OvV.rst +++ /dev/null @@ -1,2 +0,0 @@ -Fix a possible crash during the interpreter startup under a memory pressure -with ``Py_STACKREF_DEBUG`` enabled.