computing-offload/generic_vdpa/qemu/semihosting-fix-memleak-at-semihosting_arg_fallback.patch
jiangdongxu 79c4324644 add generic_vdpa basecode
Change-Id: I2d302dda68298877c65c99147f5bf22186a59aac
2024-09-19 17:19:46 +08:00

48 lines
1.8 KiB
Diff

From 47a24e233e335025ed37ab0ba4a4e728719a2ad3 Mon Sep 17 00:00:00 2001
From: qihao <qihao_yewu@cmss.chinamobile.com>
Date: Mon, 6 Nov 2023 18:14:06 +0800
Subject: [PATCH] semihosting: fix memleak at semihosting_arg_fallback
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
cheery-pick from 2eb71a0c20a6a77be128a76c1ef8fb5dc7028a8b
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>
Reviewed-by: Philippe Mathieu-Daudé <philmd@linaro.org>
Message-Id: <03d81c56bfc3d08224e4106efca5949d8894cfa5.1697801632.git.quic_mathbern@quicinc.com>
Reviewed-by: Richard Henderson <richard.henderson@linaro.org>
Signed-off-by: Alex Bennée <alex.bennee@linaro.org>
Message-Id: <20231029145033.592566-18-alex.bennee@linaro.org>
Signed-off-by: qihao_yewu <qihao_yewu@cmss.chinamobile.com>
---
semihosting/config.c | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)
diff --git a/semihosting/config.c b/semihosting/config.c
index 137171b717..303338f647 100644
--- a/semihosting/config.c
+++ b/semihosting/config.c
@@ -109,12 +109,13 @@ static int add_semihosting_arg(void *opaque,
void semihosting_arg_fallback(const char *file, const char *cmd)
{
char *cmd_token;
+ g_autofree char *cmd_dup = g_strdup(cmd);
/* argv[0] */
add_semihosting_arg(&semihosting, "arg", file, NULL);
/* split -append and initialize argv[1..n] */
- cmd_token = strtok(g_strdup(cmd), " ");
+ cmd_token = strtok(cmd_dup, " ");
while (cmd_token) {
add_semihosting_arg(&semihosting, "arg", cmd_token, NULL);
cmd_token = strtok(NULL, " ");
--
2.27.0