From ead4d6b46ac84d4c24dae8a92418ecac9766be6c Mon Sep 17 00:00:00 2001 From: Bartosz Golaszewski Date: Fri, 13 Jul 2018 10:10:34 +0200 Subject: [PATCH] bindings: python: fix a memory leak in error path We need to decref the iter object in Line.set_values() if the conversion from python to C unsigned integer fails. Signed-off-by: Bartosz Golaszewski --- bindings/python/gpiodmodule.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/bindings/python/gpiodmodule.c b/bindings/python/gpiodmodule.c index 88d90bf..3c4c254 100644 --- a/bindings/python/gpiodmodule.c +++ b/bindings/python/gpiodmodule.c @@ -1020,8 +1020,10 @@ static PyObject *gpiod_LineBulk_set_values(gpiod_LineBulkObject *self, val = PyLong_AsLong(next); Py_DECREF(next); - if (PyErr_Occurred()) + if (PyErr_Occurred()) { + Py_DECREF(iter); return NULL; + } vals[i] = (int)val; } -- 2.30.2