Skip to content

Commit 882fced

Browse files
authored
gh-116448: Handle errors correctly in os_waitid_impl in posixmodule (#116449)
1 parent 808a776 commit 882fced

File tree

1 file changed

+19
-9
lines changed

1 file changed

+19
-9
lines changed

Modules/posixmodule.c

Lines changed: 19 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -9732,15 +9732,25 @@ os_waitid_impl(PyObject *module, idtype_t idtype, id_t id, int options)
97329732
if (!result)
97339733
return NULL;
97349734

9735-
PyStructSequence_SET_ITEM(result, 0, PyLong_FromPid(si.si_pid));
9736-
PyStructSequence_SET_ITEM(result, 1, _PyLong_FromUid(si.si_uid));
9737-
PyStructSequence_SET_ITEM(result, 2, PyLong_FromLong((long)(si.si_signo)));
9738-
PyStructSequence_SET_ITEM(result, 3, PyLong_FromLong((long)(si.si_status)));
9739-
PyStructSequence_SET_ITEM(result, 4, PyLong_FromLong((long)(si.si_code)));
9740-
if (PyErr_Occurred()) {
9741-
Py_DECREF(result);
9742-
return NULL;
9743-
}
9735+
int pos = 0;
9736+
9737+
#define SET_RESULT(CALL) \
9738+
do { \
9739+
PyObject *item = (CALL); \
9740+
if (item == NULL) { \
9741+
Py_DECREF(result); \
9742+
return NULL; \
9743+
} \
9744+
PyStructSequence_SET_ITEM(result, pos++, item); \
9745+
} while(0)
9746+
9747+
SET_RESULT(PyLong_FromPid(si.si_pid));
9748+
SET_RESULT(_PyLong_FromUid(si.si_uid));
9749+
SET_RESULT(PyLong_FromLong((long)(si.si_signo)));
9750+
SET_RESULT(PyLong_FromLong((long)(si.si_status)));
9751+
SET_RESULT(PyLong_FromLong((long)(si.si_code)));
9752+
9753+
#undef SET_RESULT
97449754

97459755
return result;
97469756
}

0 commit comments

Comments
 (0)