From: Bartosz Golaszewski <bartekgola@gmail.com>
Date: Fri, 13 Jul 2018 09:21:31 +0000 (+0200)
Subject: bindings: python: fix a memory corruption
X-Git-Url: http://git.maquefel.me/?a=commitdiff_plain;h=df5d7b4f4276f24174c955e9edaa047a09c6e7c4;p=qemu-gpiodev%2Flibgpiod.git

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 <bartekgola@gmail.com>
---

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;