From: "Philippe Mathieu-Daudé" <philmd@linaro.org>
To: Matheus Tavares Bernardino <quic_mathbern@quicinc.com>,
qemu-devel@nongnu.org
Cc: bcain@quicinc.com, alex.bennee@linaro.org, qemu-trivial@nongnu.org
Subject: Re: [PATCH] semihosting: fix memleak at semihosting_arg_fallback
Date: Thu, 19 Oct 2023 23:05:21 +0200 [thread overview]
Message-ID: <dd245160-3921-ff85-dc40-b2a9e01a26a9@linaro.org> (raw)
In-Reply-To: <ebb2ec1150da633507c2b735ca8ea1cab05ec92a.1697740364.git.quic_mathbern@quicinc.com>
On 19/10/23 20:32, Matheus Tavares Bernardino wrote:
> We duplicate "cmd" as strtok may modify its argument, but we forgot
> to free it later. Furthermore, add_semihosting_arg doesn't take
> responsibility for this memory either (it strdup's the argument).
>
> Signed-off-by: Matheus Tavares Bernardino <quic_mathbern@quicinc.com>
> ---
> semihosting/config.c | 6 ++++--
> 1 file changed, 4 insertions(+), 2 deletions(-)
>
> diff --git a/semihosting/config.c b/semihosting/config.c
> index 249a377ae8..32aa210460 100644
> --- a/semihosting/config.c
> +++ b/semihosting/config.c
> @@ -112,17 +112,19 @@ static int add_semihosting_arg(void *opaque,
> /* Use strings passed via -kernel/-append to initialize semihosting.argv[] */
> void semihosting_arg_fallback(const char *file, const char *cmd)
> {
> - char *cmd_token;
Preferably using g_autofree:
g_autofree char *cmd_dup = g_strdup(cmd);
Reviewed-by: Philippe Mathieu-Daudé <philmd@linaro.org>
> + char *cmd_token, *cmd_dup;
>
> /* argv[0] */
> add_semihosting_arg(&semihosting, "arg", file, NULL);
>
> /* split -append and initialize argv[1..n] */
> - cmd_token = strtok(g_strdup(cmd), " ");
> + cmd_dup = g_strdup(cmd);
> + cmd_token = strtok(cmd_dup, " ");
> while (cmd_token) {
> add_semihosting_arg(&semihosting, "arg", cmd_token, NULL);
> cmd_token = strtok(NULL, " ");
> }
> + g_free(cmd_dup);
> }
>
> void qemu_semihosting_enable(void)
prev parent reply other threads:[~2023-10-19 21:05 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-10-19 18:32 [PATCH] semihosting: fix memleak at semihosting_arg_fallback Matheus Tavares Bernardino
2023-10-19 21:05 ` Philippe Mathieu-Daudé [this message]
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=dd245160-3921-ff85-dc40-b2a9e01a26a9@linaro.org \
--to=philmd@linaro.org \
--cc=alex.bennee@linaro.org \
--cc=bcain@quicinc.com \
--cc=qemu-devel@nongnu.org \
--cc=qemu-trivial@nongnu.org \
--cc=quic_mathbern@quicinc.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).