Skip to content

Commit dd821c2

Browse files
committed
gh-87804: Fix the refleak in error handling of _pystatvfs_fromstructstatfs
1 parent 46190d9 commit dd821c2

File tree

1 file changed

+9
-8
lines changed

1 file changed

+9
-8
lines changed

Modules/posixmodule.c

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -12916,14 +12916,15 @@ _pystatvfs_fromstructstatfs(PyObject *module, struct statfs st) {
1291612916

1291712917
_Static_assert(sizeof(st.f_blocks) == sizeof(long long), "assuming large file");
1291812918

12919-
#define SET_ITEM(v, index, item) \
12920-
do { \
12921-
if (item == NULL) { \
12922-
Py_DECREF(v); \
12923-
return NULL; \
12924-
} \
12925-
PyStructSequence_SET_ITEM(v, index, item); \
12926-
} while (0) \
12919+
#define SET_ITEM(v, index, expr) \
12920+
do { \
12921+
PyObject *obj = (expr); \
12922+
if (obj == NULL || PyErr_Occurred()) { \
12923+
Py_DECREF(v); \
12924+
return NULL; \
12925+
} \
12926+
PyStructSequence_SET_ITEM(v, (index), obj); \
12927+
} while (0) \
1292712928

1292812929
SET_ITEM(v, 0, PyLong_FromLong((long) st.f_iosize));
1292912930
SET_ITEM(v, 1, PyLong_FromLong((long) st.f_bsize));

0 commit comments

Comments
 (0)