mail archive of the barebox mailing list
 help / color / mirror / Atom feed
From: Jules Maselbas <jmaselbas@zdiv.net>
To: barebox@lists.infradead.org
Cc: Jules Maselbas <jmaselbas@zdiv.net>
Subject: [PATCH] commands: of_display_timings: prevent memory leak
Date: Fri, 14 Mar 2025 23:30:07 +0100	[thread overview]
Message-ID: <20250314223007.26457-1-jmaselbas@zdiv.net> (raw)

memory could be leaked if the S option is passed several time.
Also replace the xzalloc + strcpy call with a call to xstrdup.

Signed-off-by: Jules Maselbas <jmaselbas@zdiv.net>
---
 commands/of_display_timings.c | 7 +++----
 1 file changed, 3 insertions(+), 4 deletions(-)

diff --git a/commands/of_display_timings.c b/commands/of_display_timings.c
index 232074fce7..5998d42ffe 100644
--- a/commands/of_display_timings.c
+++ b/commands/of_display_timings.c
@@ -42,7 +42,7 @@ static int do_of_display_timings(int argc, char *argv[])
 	struct device_node *root = NULL;
 	struct device_node *display = NULL;
 	struct device_node *timings = NULL;
-	char *timingpath = NULL;
+	const char *timingpath = NULL;
 	char *dtbfile = NULL;
 
 	while ((opt = getopt(argc, argv, "sS:lf:")) > 0) {
@@ -57,8 +57,7 @@ static int do_of_display_timings(int argc, char *argv[])
 			selected = 1;
 			break;
 		case 'S':
-			timingpath = xzalloc(strlen(optarg) + 1);
-			strcpy(timingpath, optarg);
+			timingpath = optarg;
 			break;
 		default:
 			return COMMAND_ERROR_USAGE;
@@ -108,7 +107,7 @@ static int do_of_display_timings(int argc, char *argv[])
 	}
 
 	if (timingpath)
-		of_register_fixup(of_display_timing, timingpath);
+		of_register_fixup(of_display_timing, xstrdup(timingpath));
 
 	return 0;
 }
-- 
2.48.1




                 reply	other threads:[~2025-03-14 22:31 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

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=20250314223007.26457-1-jmaselbas@zdiv.net \
    --to=jmaselbas@zdiv.net \
    --cc=barebox@lists.infradead.org \
    /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