Linux GPIO subsystem development
 help / color / mirror / Atom feed
* [PATCH libgpiod] bindings: python: don't decref objects on PyList_SetItem() failure
@ 2026-05-11 11:15 Bartosz Golaszewski
  2026-05-11 12:29 ` Vincent Fazio
  2026-05-12  7:30 ` Bartosz Golaszewski
  0 siblings, 2 replies; 3+ messages in thread
From: Bartosz Golaszewski @ 2026-05-11 11:15 UTC (permalink / raw)
  To: Linus Walleij, Bartosz Golaszewski, Vincent Fazio
  Cc: linux-gpio, 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.

Fixes: b7ba732e6a93 ("treewide: libgpiod v2 implementation")
Closes: https://github.com/brgl/libgpiod/issues/187
Signed-off-by: Bartosz Golaszewski <bartosz.golaszewski@oss.qualcomm.com>
---
 bindings/python/gpiod/ext/request.c | 3 ---
 1 file changed, 3 deletions(-)

diff --git a/bindings/python/gpiod/ext/request.c b/bindings/python/gpiod/ext/request.c
index 46e07ae..7ba3dde 100644
--- a/bindings/python/gpiod/ext/request.c
+++ b/bindings/python/gpiod/ext/request.c
@@ -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;
-- 
2.47.3


^ permalink raw reply related	[flat|nested] 3+ messages in thread

* RE: [PATCH libgpiod] bindings: python: don't decref objects on PyList_SetItem() failure
  2026-05-11 11:15 [PATCH libgpiod] bindings: python: don't decref objects on PyList_SetItem() failure Bartosz Golaszewski
@ 2026-05-11 12:29 ` Vincent Fazio
  2026-05-12  7:30 ` Bartosz Golaszewski
  1 sibling, 0 replies; 3+ messages in thread
From: Vincent Fazio @ 2026-05-11 12:29 UTC (permalink / raw)
  To: Bartosz Golaszewski, Linus Walleij, Bartosz Golaszewski
  Cc: linux-gpio@vger.kernel.org



> -----Original Message-----
> From: Bartosz Golaszewski <bartosz.golaszewski@oss.qualcomm.com>
> Sent: Monday, May 11, 2026 6:16 AM
> To: Linus Walleij <linusw@kernel.org>; Bartosz Golaszewski <brgl@kernel.org>;
> Vincent Fazio <vfazio@xes-inc.com>
> Cc: linux-gpio@vger.kernel.org; Bartosz Golaszewski
> <bartosz.golaszewski@oss.qualcomm.com>
> Subject: [PATCH libgpiod] 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.
> 
> Fixes: b7ba732e6a93 ("treewide: libgpiod v2 implementation")
> Closes: https://github.com/brgl/libgpiod/issues/187
> Signed-off-by: Bartosz Golaszewski
> <bartosz.golaszewski@oss.qualcomm.com>

Reviewed-by: Vincent Fazio <vfazio@xes-inc.com>



^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH libgpiod] bindings: python: don't decref objects on PyList_SetItem() failure
  2026-05-11 11:15 [PATCH libgpiod] bindings: python: don't decref objects on PyList_SetItem() failure Bartosz Golaszewski
  2026-05-11 12:29 ` Vincent Fazio
@ 2026-05-12  7:30 ` Bartosz Golaszewski
  1 sibling, 0 replies; 3+ messages in thread
From: Bartosz Golaszewski @ 2026-05-12  7:30 UTC (permalink / raw)
  To: Linus Walleij, Bartosz Golaszewski, Vincent Fazio,
	Bartosz Golaszewski
  Cc: linux-gpio


On Mon, 11 May 2026 13:15:37 +0200, Bartosz Golaszewski wrote:
> 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,
-- 
Bartosz Golaszewski <bartosz.golaszewski@oss.qualcomm.com>

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2026-05-12  7:30 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-05-11 11:15 [PATCH libgpiod] bindings: python: don't decref objects on PyList_SetItem() failure Bartosz Golaszewski
2026-05-11 12:29 ` Vincent Fazio
2026-05-12  7:30 ` Bartosz Golaszewski

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox