From ed1add46b16ce9b72ab1ce2dc734106724743d73 Mon Sep 17 00:00:00 2001 From: sobolevn Date: Thu, 11 Jun 2026 18:48:08 +0300 Subject: [PATCH] gh-151126: Fix missing memory error in `os._path_splitroot` (GH-151339) (cherry picked from commit 10595b1cb7ac04ba9a3ef3f7da4fa31c9966300d) Co-authored-by: sobolevn --- .../next/Library/2026-06-11-16-25-38.gh-issue-151126.bh_Usy.rst | 2 ++ Modules/posixmodule.c | 2 +- 2 files changed, 3 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 000000000000000..25149057aa7d092 --- /dev/null +++ b/Misc/NEWS.d/next/Library/2026-06-11-16-25-38.gh-issue-151126.bh_Usy.rst @@ -0,0 +1,2 @@ +Fix a crash when :exc:`MemoryError` in :func:`!os._path_splitroot` +was not set properly. diff --git a/Modules/posixmodule.c b/Modules/posixmodule.c index 86187cbeb47a5b5..3fcf19e63c19aef 100644 --- a/Modules/posixmodule.c +++ b/Modules/posixmodule.c @@ -5133,7 +5133,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'/')) {