]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
gh-151126: Fix missing memory error in `os._path_splitroot` (#151339)
authorsobolevn <mail@sobolevn.me>
Thu, 11 Jun 2026 15:48:08 +0000 (18:48 +0300)
committerGitHub <noreply@github.com>
Thu, 11 Jun 2026 15:48:08 +0000 (15:48 +0000)
Misc/NEWS.d/next/Library/2026-06-11-16-25-38.gh-issue-151126.bh_Usy.rst [new file with mode: 0644]
Modules/posixmodule.c

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 (file)
index 0000000..2514905
--- /dev/null
@@ -0,0 +1,2 @@
+Fix a crash when :exc:`MemoryError` in :func:`!os._path_splitroot`
+was not set properly.
index f9f53ca5cb5e49bcad9a6d2c9bf8ad6aa0d083cf..1f1b7fa729c01c8e0ab227a6fb24ca709ca3af8d 100644 (file)
@@ -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'/')) {