From 8ed8cfc592537cf41f5a3e084efde9d3d4f78726 Mon Sep 17 00:00:00 2001 From: sobolevn Date: Thu, 11 Jun 2026 16:25:02 +0300 Subject: [PATCH 1/2] gh-151126: Fix missing memory error in `os._path_splitroot` --- .../next/Library/2026-06-11-16-25-38.gh-issue-151126.bh_Usy.rst | 1 + Modules/posixmodule.c | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) create mode 100644 Misc/NEWS.d/next/Library/2026-06-11-16-25-38.gh-issue-151126.bh_Usy.rst diff --git a/Misc/NEWS.d/next/Library/2026-06-11-16-25-38.gh-issue-151126.bh_Usy.rst b/Misc/NEWS.d/next/Library/2026-06-11-16-25-38.gh-issue-151126.bh_Usy.rst new file mode 100644 index 00000000000000..223930b6ec84ac --- /dev/null +++ b/Misc/NEWS.d/next/Library/2026-06-11-16-25-38.gh-issue-151126.bh_Usy.rst @@ -0,0 +1 @@ +Fix :exc:`MemoryError` in :func:`!os._path_splitroot`. diff --git a/Modules/posixmodule.c b/Modules/posixmodule.c index f9f53ca5cb5e49..1f1b7fa729c01c 100644 --- a/Modules/posixmodule.c +++ b/Modules/posixmodule.c @@ -5699,7 +5699,7 @@ os__path_splitroot_impl(PyObject *module, path_t *path) buffer = (wchar_t*)PyMem_Malloc(sizeof(wchar_t) * (wcslen(path->wide) + 1)); if (!buffer) { - return NULL; + return PyErr_NoMemory(); } wcscpy(buffer, path->wide); for (wchar_t *p = wcschr(buffer, L'/'); p; p = wcschr(p, L'/')) { From 8e6f6bb63e336ebd5849f3f233e82e26e1c98000 Mon Sep 17 00:00:00 2001 From: sobolevn Date: Thu, 11 Jun 2026 18:21:56 +0300 Subject: [PATCH 2/2] Update 2026-06-11-16-25-38.gh-issue-151126.bh_Usy.rst --- .../Library/2026-06-11-16-25-38.gh-issue-151126.bh_Usy.rst | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/Misc/NEWS.d/next/Library/2026-06-11-16-25-38.gh-issue-151126.bh_Usy.rst b/Misc/NEWS.d/next/Library/2026-06-11-16-25-38.gh-issue-151126.bh_Usy.rst index 223930b6ec84ac..25149057aa7d09 100644 --- a/Misc/NEWS.d/next/Library/2026-06-11-16-25-38.gh-issue-151126.bh_Usy.rst +++ b/Misc/NEWS.d/next/Library/2026-06-11-16-25-38.gh-issue-151126.bh_Usy.rst @@ -1 +1,2 @@ -Fix :exc:`MemoryError` in :func:`!os._path_splitroot`. +Fix a crash when :exc:`MemoryError` in :func:`!os._path_splitroot` +was not set properly.