Linux GPIO subsystem development
 help / color / mirror / Atom feed
From: Bartosz Golaszewski <bartosz.golaszewski@oss.qualcomm.com>
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
Date: Mon, 11 May 2026 13:15:37 +0200	[thread overview]
Message-ID: <20260511111538.60844-1-bartosz.golaszewski@oss.qualcomm.com> (raw)

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


             reply	other threads:[~2026-05-11 11:15 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-05-11 11:15 Bartosz Golaszewski [this message]
2026-05-11 12:29 ` [PATCH libgpiod] bindings: python: don't decref objects on PyList_SetItem() failure Vincent Fazio
2026-05-12  7:30 ` Bartosz Golaszewski

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20260511111538.60844-1-bartosz.golaszewski@oss.qualcomm.com \
    --to=bartosz.golaszewski@oss.qualcomm.com \
    --cc=brgl@kernel.org \
    --cc=linusw@kernel.org \
    --cc=linux-gpio@vger.kernel.org \
    --cc=vfazio@xes-inc.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox