From 4448205d95e87ca3d1e23cc350af59ec48b3321b Mon Sep 17 00:00:00 2001 From: Ivy Xu Date: Mon, 22 Jun 2026 21:59:22 +0800 Subject: [PATCH] gh-151126: Fix missing `PyErr_NoMemory` in `getpath.c` (#151590) --- .../2026-06-17-16-26-45.gh-issue-151126.Yc_6wC.rst | 2 ++ Modules/getpath.c | 1 + 2 files changed, 3 insertions(+) create mode 100644 Misc/NEWS.d/next/Core_and_Builtins/2026-06-17-16-26-45.gh-issue-151126.Yc_6wC.rst diff --git a/Misc/NEWS.d/next/Core_and_Builtins/2026-06-17-16-26-45.gh-issue-151126.Yc_6wC.rst b/Misc/NEWS.d/next/Core_and_Builtins/2026-06-17-16-26-45.gh-issue-151126.Yc_6wC.rst new file mode 100644 index 000000000000..29bb03d2d408 --- /dev/null +++ b/Misc/NEWS.d/next/Core_and_Builtins/2026-06-17-16-26-45.gh-issue-151126.Yc_6wC.rst @@ -0,0 +1,2 @@ +Avoid possible crash in ``getpath.c`` where a device has no memory left. Now +it properly raises a :exc:`MemoryError`. Patch by Ivy Xu. diff --git a/Modules/getpath.c b/Modules/getpath.c index 1e75993480ae..0c80678a678d 100644 --- a/Modules/getpath.c +++ b/Modules/getpath.c @@ -368,6 +368,7 @@ getpath_readlines(PyObject *Py_UNUSED(self), PyObject *args) if (!buffer) { Py_DECREF(r); fclose(fp); + PyErr_NoMemory(); return NULL; } -- 2.47.3