linux-gpio.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Iker Pedrosa <ikerpedrosam@gmail.com>
To: brgl@bgdev.pl
Cc: Iker Pedrosa <ikerpedrosam@gmail.com>,
	ipedrosa@redhat.com, javierm@redhat.com, perobins@redhat.com,
	linux-gpio@vger.kernel.org, warthog618@gmail.com
Subject: [PATCH libgpiod v2 1/4] bindings: python: gpiod: avoid use after free
Date: Mon, 29 Jul 2024 12:57:16 +0200	[thread overview]
Message-ID: <3d8b12dd60eec59d4184c0bcc7d575b4eccbc22c.1722250385.git.ikerpedrosam@gmail.com> (raw)
In-Reply-To: <cover.1722250385.git.ikerpedrosam@gmail.com>

`req_cfg` variable is freed and then used, which would generate an
error. Avoid this problem by freeing when the variable will no longer be
used.

Signed-off-by: Iker Pedrosa <ikerpedrosam@gmail.com>
Reviewed-by: Kent Gibson <warthog618@gmail.com>
---
 bindings/python/gpiod/ext/chip.c | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)

diff --git a/bindings/python/gpiod/ext/chip.c b/bindings/python/gpiod/ext/chip.c
index 28cf504..e8eaad8 100644
--- a/bindings/python/gpiod/ext/chip.c
+++ b/bindings/python/gpiod/ext/chip.c
@@ -274,14 +274,16 @@ static PyObject *chip_request_lines(chip_object *self, PyObject *args)
 	Py_BEGIN_ALLOW_THREADS;
 	request = gpiod_chip_request_lines(self->chip, req_cfg, line_cfg);
 	Py_END_ALLOW_THREADS;
-	gpiod_request_config_free(req_cfg);
-	if (!request)
+	if (!request) {
+		gpiod_request_config_free(req_cfg);
 		return Py_gpiod_SetErrFromErrno();
+	}
 
 	req_obj = Py_gpiod_MakeRequestObject(request,
 			gpiod_request_config_get_event_buffer_size(req_cfg));
 	if (!req_obj)
 		gpiod_line_request_release(request);
+	gpiod_request_config_free(req_cfg);
 
 	return req_obj;
 }
-- 
2.45.2


  reply	other threads:[~2024-07-29 10:58 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-07-29 10:57 [PATCH libgpiod v2 0/4] Fix issues detected by static analyzer Iker Pedrosa
2024-07-29 10:57 ` Iker Pedrosa [this message]
2024-07-29 10:57 ` [PATCH libgpiod v2 2/4] lib: line-info strings termination Iker Pedrosa
2024-07-29 10:57 ` [PATCH libgpiod v2 3/4] lib: chip-info " Iker Pedrosa
2024-07-29 10:57 ` [PATCH libgpiod v2 4/4] tools: free to avoid leak Iker Pedrosa
2024-07-31  9:21 ` [PATCH libgpiod v2 0/4] Fix issues detected by static analyzer 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=3d8b12dd60eec59d4184c0bcc7d575b4eccbc22c.1722250385.git.ikerpedrosam@gmail.com \
    --to=ikerpedrosam@gmail.com \
    --cc=brgl@bgdev.pl \
    --cc=ipedrosa@redhat.com \
    --cc=javierm@redhat.com \
    --cc=linux-gpio@vger.kernel.org \
    --cc=perobins@redhat.com \
    --cc=warthog618@gmail.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;
as well as URLs for NNTP newsgroup(s).