summaryrefslogtreecommitdiffstats
path: root/Modules/mmapmodule.c
diff options
context:
space:
mode:
authorSerhiy Storchaka <storchaka@gmail.com>2023-08-26 21:35:06 (GMT)
committerGitHub <noreply@github.com>2023-08-26 21:35:06 (GMT)
commit2b15536fa94d07e9e286826c23507402313ec7f4 (patch)
treebed59616b5e2b833e15cc6b10f0dccfca8faa9fb /Modules/mmapmodule.c
parente407cea1938b80b1d469f148a4ea65587820e3eb (diff)
downloadcpython-2b15536fa94d07e9e286826c23507402313ec7f4.zip
cpython-2b15536fa94d07e9e286826c23507402313ec7f4.tar.gz
cpython-2b15536fa94d07e9e286826c23507402313ec7f4.tar.bz2
gh-107913: Fix possible losses of OSError error codes (GH-107930)
Functions like PyErr_SetFromErrno() and SetFromWindowsErr() should be called immediately after using the C API which sets errno or the Windows error code.
Diffstat (limited to 'Modules/mmapmodule.c')
-rw-r--r--Modules/mmapmodule.c2
1 files changed, 2 insertions, 0 deletions
diff --git a/Modules/mmapmodule.c b/Modules/mmapmodule.c
index 44d5b26..c8cd7e5 100644
--- a/Modules/mmapmodule.c
+++ b/Modules/mmapmodule.c
@@ -1356,6 +1356,7 @@ new_mmap_object(PyTypeObject *type, PyObject *args, PyObject *kwdict)
m_obj->data = mmap(NULL, map_size, prot, flags, fd, offset);
Py_END_ALLOW_THREADS
+ int saved_errno = errno;
if (devzero != -1) {
close(devzero);
}
@@ -1363,6 +1364,7 @@ new_mmap_object(PyTypeObject *type, PyObject *args, PyObject *kwdict)
if (m_obj->data == (char *)-1) {
m_obj->data = NULL;
Py_DECREF(m_obj);
+ errno = saved_errno;
PyErr_SetFromErrno(PyExc_OSError);
return NULL;
}