bindings: python: don't decref objects on PyList_SetItem() failure
PATCH 1/1 bindings: python: don't decref objects on PyList_SetItem() failure
PyList_SetItem() steals the reference to the object we want to add regardless of whether it succeeds or fails. Don't decrease the reference count of the object we failed to add in error path.
--- bindings/python/gpiod/ext/request.c | 3 --- 1 file changed, 3 deletions(-)
bindings/python/gpiod/ext/request.c +0 -3
@@ -81,7 +81,6 @@ static PyObject *request_offsets(request_object *self, void *Py_UNUSED(ignored)) ret =PyList_SetItem (lines, i, line);if (ret) { -Py_DECREF (line);Py_DECREF (lines);PyMem_Free (offsets);return NULL ;
@@ -194,7 +193,6 @@ static PyObject *request_get_values(request_object *self, PyObject *args) ret =PyList_SetItem (values, pos, val);if (ret) { -Py_DECREF (val);Py_DECREF (type);return NULL ; }
@@ -335,7 +333,6 @@ static PyObject *request_read_edge_events(request_object *self, PyObject *args) ret =PyList_SetItem (events, i, event_obj);if (ret) { -Py_DECREF (event_obj);Py_DECREF (events);Py_DECREF (type);return NULL ;
Signature · 1 line
2.47.3
Quoted 12 lines
-----Original Message-----
From: Bartosz Golaszewski <[email protected]>
Sent: Monday, May 11, 2026 6:16 AM
To: Linus Walleij <[email protected]>; Bartosz Golaszewski <[email protected]>; Vincent Fazio <[email protected]>
Cc: [email protected]; Bartosz Golaszewski <[email protected]>
Subject: [PATCH libgpiod] bindings: python: don't decref objects onPyList_SetItem()failure
Quoted 8 lines
PyList_SetItem()steals the reference to the object we want to add regardless of whether it succeeds or fails. Don't decrease the reference count of the object we failed to add in error path.Fixes b7ba732e6a93 ("treewide: libgpiod v2 implementation")Signed-off-by Bartosz Golaszewski
Bartosz Golaszewski
AppliedQuoted 5 lines · Bartosz Golaszewski
PyList_SetItem()steals the reference to the object we want to add regardless of whether it succeeds or fails. Don't decrease the reference count of the object we failed to add in error path.
Applied, thanks!
[1/1] bindings: python: don't decref objects on PyList_SetItem() failure
https://git.kernel.org/brgl/c/a7b443f2c7c9c3d9f7a8218568cfaad7bd6fe1cb
Best regards,
Signature · 1 line
Bartosz Golaszewski <[email protected]>