[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:
Miss Islington (bot) 2023-08-26 16:24:40 -07:00 committed by GitHub
parent bbdd8895a5
commit 3e20303717
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
17 changed files with 129 additions and 75 deletions

View file

@ -1292,8 +1292,8 @@ newPyEpoll_Object(PyTypeObject *type, int sizehint, SOCKET fd)
self->epfd = fd;
}
if (self->epfd < 0) {
Py_DECREF(self);
PyErr_SetFromErrno(PyExc_OSError);
Py_DECREF(self);
return NULL;
}
@ -1971,8 +1971,8 @@ newKqueue_Object(PyTypeObject *type, SOCKET fd)
self->kqfd = fd;
}
if (self->kqfd < 0) {
Py_DECREF(self);
PyErr_SetFromErrno(PyExc_OSError);
Py_DECREF(self);
return NULL;
}