mirror of
https://github.com/python/cpython.git
synced 2025-08-04 00:48:58 +00:00
[3.11] gh-107913: Fix possible losses of OSError error codes (GH-107930) (GH-108524)
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
)
This commit is contained in:
parent
8a275f7c01
commit
b9fc536399
17 changed files with 129 additions and 77 deletions
|
@ -1687,6 +1687,7 @@ _Py_fopen_obj(PyObject *path, const char *mode)
|
|||
Py_END_ALLOW_THREADS
|
||||
} while (f == NULL
|
||||
&& errno == EINTR && !(async_err = PyErr_CheckSignals()));
|
||||
int saved_errno = errno;
|
||||
#if !USE_UNICODE_WCHAR_CACHE
|
||||
PyMem_Free(wpath);
|
||||
#endif /* USE_UNICODE_WCHAR_CACHE */
|
||||
|
@ -1711,13 +1712,14 @@ _Py_fopen_obj(PyObject *path, const char *mode)
|
|||
Py_END_ALLOW_THREADS
|
||||
} while (f == NULL
|
||||
&& errno == EINTR && !(async_err = PyErr_CheckSignals()));
|
||||
|
||||
int saved_errno = errno;
|
||||
Py_DECREF(bytes);
|
||||
#endif
|
||||
if (async_err)
|
||||
return NULL;
|
||||
|
||||
if (f == NULL) {
|
||||
errno = saved_errno;
|
||||
PyErr_SetFromErrnoWithFilenameObject(PyExc_OSError, path);
|
||||
return NULL;
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue