From: Sascha Hauer <s.hauer@pengutronix.de>
To: BAREBOX <barebox@lists.infradead.org>
Subject: [PATCH 4/4] bfetch: fix memory leak
Date: Fri, 07 Nov 2025 13:00:54 +0100 [thread overview]
Message-ID: <20251107-memleaks-v1-4-c7b74a2ae9db@pengutronix.de> (raw)
In-Reply-To: <20251107-memleaks-v1-0-c7b74a2ae9db@pengutronix.de>
string_list_join() returns an allocated string. Free it after usage.
Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
---
commands/bfetch.c | 28 +++++++++++++++++++++++-----
1 file changed, 23 insertions(+), 5 deletions(-)
diff --git a/commands/bfetch.c b/commands/bfetch.c
index a44d5a000667c0802a3795bbb64ead9362ebb944..19647deecf0a94e6175fc4e1fad8a4a512c4c3df 100644
--- a/commands/bfetch.c
+++ b/commands/bfetch.c
@@ -171,9 +171,17 @@ static inline bool __print_string_list(unsigned *line, const char *key,
struct string_list *sl,
const char *joinstr)
{
+ char *str;
+
if (string_list_empty(sl))
return false;
- print_line(key, "%s", string_list_join(sl, joinstr));
+
+ str = string_list_join(sl, joinstr);
+
+ print_line(key, "%s", str);
+
+ free(str);
+
return true;
}
#define print_string_list(k, sl, js) __print_string_list(line, k, sl, js)
@@ -309,8 +317,13 @@ static void print_shell_console(unsigned *line)
for_each_console(console)
string_list_add(&sl, console->devfs.name);
- if (!string_list_empty(&sl))
- print_line("Consoles", "%s", string_list_join(&sl, " "));
+ if (!string_list_empty(&sl)) {
+ char *str = string_list_join(&sl, " ");
+
+ print_line("Consoles", "%s", str);
+
+ free(str);
+ }
string_list_free(&sl);
}
@@ -332,8 +345,13 @@ static void print_framebuffers(unsigned *line)
info->bits_per_pixel);
}
- if (!string_list_empty(&sl))
- print_line("Framebuffers", "%s", string_list_join(&sl, ", "));
+ if (!string_list_empty(&sl)) {
+ char *str = string_list_join(&sl, ", ");
+
+ print_line("Framebuffers", "%s", str);
+
+ free(str);
+ }
string_list_free(&sl);
}
--
2.47.3
next prev parent reply other threads:[~2025-11-07 12:01 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-11-07 12:00 [PATCH 0/4] fix some memory leaks Sascha Hauer
2025-11-07 12:00 ` [PATCH 1/4] tlv: fix memory leak Sascha Hauer
2025-11-07 12:00 ` [PATCH 2/4] of: free of_fixup in of_unregister_fixup() Sascha Hauer
2025-11-07 12:00 ` [PATCH 3/4] bobject: free object name in bobject_del() Sascha Hauer
2025-11-10 13:48 ` Sascha Hauer
2025-11-07 12:00 ` Sascha Hauer [this message]
2025-11-10 13:46 ` [PATCH 0/4] fix some memory leaks Sascha Hauer
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=20251107-memleaks-v1-4-c7b74a2ae9db@pengutronix.de \
--to=s.hauer@pengutronix.de \
--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