summaryrefslogtreecommitdiffstats
path: root/Modules/_multiprocessing/semaphore.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/_multiprocessing/semaphore.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/_multiprocessing/semaphore.c')
-rw-r--r--Modules/_multiprocessing/semaphore.c9
1 files changed, 5 insertions, 4 deletions
diff --git a/Modules/_multiprocessing/semaphore.c b/Modules/_multiprocessing/semaphore.c
index 771f86e..d22b8d1 100644
--- a/Modules/_multiprocessing/semaphore.c
+++ b/Modules/_multiprocessing/semaphore.c
@@ -516,12 +516,12 @@ _multiprocessing_SemLock_impl(PyTypeObject *type, int kind, int value,
return result;
failure:
- if (handle != SEM_FAILED)
- SEM_CLOSE(handle);
- PyMem_Free(name_copy);
if (!PyErr_Occurred()) {
_PyMp_SetError(NULL, MP_STANDARD_ERROR);
}
+ if (handle != SEM_FAILED)
+ SEM_CLOSE(handle);
+ PyMem_Free(name_copy);
return NULL;
}
@@ -556,8 +556,9 @@ _multiprocessing_SemLock__rebuild_impl(PyTypeObject *type, SEM_HANDLE handle,
if (name != NULL) {
handle = sem_open(name, 0);
if (handle == SEM_FAILED) {
+ PyErr_SetFromErrno(PyExc_OSError);
PyMem_Free(name_copy);
- return PyErr_SetFromErrno(PyExc_OSError);
+ return NULL;
}
}
#endif