bindings: python: fix a memory leak in error path
authorBartosz Golaszewski <bartekgola@gmail.com>
Fri, 13 Jul 2018 08:10:34 +0000 (10:10 +0200)
committerBartosz Golaszewski <bartekgola@gmail.com>
Fri, 13 Jul 2018 08:11:12 +0000 (10:11 +0200)
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 <bartekgola@gmail.com>
bindings/python/gpiodmodule.c

index 88d90bfa5f9e8c1ac335e510950bb5652237199e..3c4c254911bddf37a3091236aaa4351c21892002 100644 (file)
@@ -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;
        }