Skip to content

Commit c27d05a

Browse files
committed
gh-151126: Fix a possible crash during the startup with no memory under Py_STACKREF_DEBUG
1 parent 95bfaff commit c27d05a

2 files changed

Lines changed: 8 additions & 0 deletions

File tree

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
Fix a possible crash during the interpreter startup under a memory pressure
2+
with ``Py_STACKREF_DEBUG`` enabled.

Python/pystate.c

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -656,6 +656,9 @@ init_interpreter(PyInterpreterState *interp,
656656
NULL,
657657
&alloc
658658
);
659+
if (interp->open_stackrefs_table == NULL) {
660+
return _PyStatus_NO_MEMORY();
661+
}
659662
# ifdef Py_STACKREF_CLOSE_DEBUG
660663
interp->closed_stackrefs_table = _Py_hashtable_new_full(
661664
_Py_hashtable_hash_ptr,
@@ -664,6 +667,9 @@ init_interpreter(PyInterpreterState *interp,
664667
NULL,
665668
&alloc
666669
);
670+
if (interp->closed_stackrefs_table == NULL) {
671+
return _PyStatus_NO_MEMORY();
672+
}
667673
# endif
668674
_Py_stackref_associate(interp, Py_None, PyStackRef_None);
669675
_Py_stackref_associate(interp, Py_False, PyStackRef_False);

0 commit comments

Comments
 (0)