From df5d7b4f4276f24174c955e9edaa047a09c6e7c4 Mon Sep 17 00:00:00 2001 From: Bartosz Golaszewski Date: Fri, 13 Jul 2018 11:21:31 +0200 Subject: [PATCH] bindings: python: fix a memory corruption PyList_GetItem() returns a borrowed reference so we need to increase the reference count on the returned object before DECREF'ing the list object itself This fixes random 'free(): invalid pointer' errors. Signed-off-by: Bartosz Golaszewski --- bindings/python/gpiodmodule.c | 1 + 1 file changed, 1 insertion(+) diff --git a/bindings/python/gpiodmodule.c b/bindings/python/gpiodmodule.c index 3c4c254..d4af5a7 100644 --- a/bindings/python/gpiodmodule.c +++ b/bindings/python/gpiodmodule.c @@ -399,6 +399,7 @@ static PyObject *gpiod_Line_get_value(gpiod_LineObject *self) return NULL; ret = PyList_GetItem(vals, 0); + Py_INCREF(ret); Py_DECREF(vals); return ret; -- 2.30.2