From 2bcdda7b1a8414b7d42fb38eed0cccd81b968a18 Mon Sep 17 00:00:00 2001 From: Nikita Sobolev Date: Mon, 12 Feb 2024 19:27:27 +0300 Subject: [PATCH] gh-87804: Fix the refleak in error handling of `_pystatvfs_fromstructstatfs` (#115335) It was the macro expansion! Sorry! --- Modules/posixmodule.c | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/Modules/posixmodule.c b/Modules/posixmodule.c index 17032d9d490c782..ef6d65623bf0388 100644 --- a/Modules/posixmodule.c +++ b/Modules/posixmodule.c @@ -12916,14 +12916,15 @@ _pystatvfs_fromstructstatfs(PyObject *module, struct statfs st) { _Static_assert(sizeof(st.f_blocks) == sizeof(long long), "assuming large file"); -#define SET_ITEM(v, index, item) \ - do { \ - if (item == NULL) { \ - Py_DECREF(v); \ - return NULL; \ - } \ - PyStructSequence_SET_ITEM(v, index, item); \ - } while (0) \ +#define SET_ITEM(SEQ, INDEX, EXPR) \ + do { \ + PyObject *obj = (EXPR); \ + if (obj == NULL) { \ + Py_DECREF((SEQ)); \ + return NULL; \ + } \ + PyStructSequence_SET_ITEM((SEQ), (INDEX), obj); \ + } while (0) SET_ITEM(v, 0, PyLong_FromLong((long) st.f_iosize)); SET_ITEM(v, 1, PyLong_FromLong((long) st.f_bsize));