mirror of
https://github.com/python/cpython.git
synced 2025-10-17 20:28:43 +00:00
[3.12] gh-107913: Fix possible losses of OSError error codes (GH-107930) (#108523)
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.
(cherry picked from commit 2b15536fa9
)
Co-authored-by: Serhiy Storchaka <storchaka@gmail.com>
This commit is contained in:
parent
bbdd8895a5
commit
3e20303717
17 changed files with 129 additions and 75 deletions
|
@ -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;
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue