From 5234c0013468a57e3a4fe464c16d4919dc1c8942 Mon Sep 17 00:00:00 2001 From: Iustin Pop Date: Mon, 10 Oct 2022 00:07:06 +0300 Subject: [PATCH] Don't leak temporary tuples in get_all() (#36) Issue #35 found two instances of memory leaks. This fixes the first one, which arguably is a more realistic case. --- xattr.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/xattr.c b/xattr.c index ab21fac..1cb5088 100644 --- a/xattr.c +++ b/xattr.c @@ -634,11 +634,12 @@ get_all(PyObject *self, PyObject *args, PyObject *keywds) Py_DECREF(mylist); goto free_buf_val; } - if(PyList_Append(mylist, my_tuple) < 0) { + int lappend_ret = PyList_Append(mylist, my_tuple); + Py_DECREF(my_tuple); + if(lappend_ret < 0) { Py_DECREF(mylist); goto free_buf_val; } - Py_DECREF(my_tuple); } /* Successful exit */ -- 2.39.2