diff --git a/Misc/NEWS.d/next/Core_and_Builtins/2026-07-26-12-00-02.gh-issue-151673.g7h8i9.rst b/Misc/NEWS.d/next/Core_and_Builtins/2026-07-26-12-00-02.gh-issue-151673.g7h8i9.rst new file mode 100644 index 00000000000000..1126f04790647d --- /dev/null +++ b/Misc/NEWS.d/next/Core_and_Builtins/2026-07-26-12-00-02.gh-issue-151673.g7h8i9.rst @@ -0,0 +1 @@ +Fix a crash in the warnings module when allocating a synthetic filename fails under memory pressure. diff --git a/Python/_warnings.c b/Python/_warnings.c index 4f6de50efa14a8..af546acd2db3a5 100644 --- a/Python/_warnings.c +++ b/Python/_warnings.c @@ -1035,6 +1035,9 @@ setup_context(Py_ssize_t stack_level, globals = interp->sysdict; *filename = PyUnicode_FromString(""); *lineno = 0; + if (*filename == NULL) { + return 0; /* nothing else allocated yet on this path */ + } } else { globals = f->f_frame->f_globals;