[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PATCH v2 17/19] semihosting: fix memleak at semihosting_arg_fallback
|
From: |
Alex Bennée |
|
Subject: |
[PATCH v2 17/19] semihosting: fix memleak at semihosting_arg_fallback |
|
Date: |
Sun, 29 Oct 2023 14:50:31 +0000 |
From: Matheus Tavares Bernardino <quic_mathbern@quicinc.com>
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: <20231028103311.347104-16-alex.bennee@linaro.org>
---
semihosting/config.c | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)
diff --git a/semihosting/config.c b/semihosting/config.c
index 249a377ae8..56283b5c3c 100644
--- a/semihosting/config.c
+++ b/semihosting/config.c
@@ -113,12 +113,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.39.2
- [PATCH v2 01/19] tests/vm/openbsd: Use the system dtc package, (continued)
- [PATCH v2 01/19] tests/vm/openbsd: Use the system dtc package, Alex Bennée, 2023/10/29
- [PATCH v2 03/19] gitlab: split alpha testing into a legacy container, Alex Bennée, 2023/10/29
- [PATCH v2 09/19] tests/docker: use debian-all-test-cross for hppa, Alex Bennée, 2023/10/29
- [PATCH v2 10/19] tests/docker: use debian-all-test-cross for m68k, Alex Bennée, 2023/10/29
- [PATCH v2 07/19] tests/docker: move sh4 to use debian-legacy-test-cross, Alex Bennée, 2023/10/29
- [PATCH v2 11/19] tests/docker: use debian-all-test-cross for mips64, Alex Bennée, 2023/10/29
- [PATCH v2 14/19] tests/docker: use debian-all-test-cross for sparc64, Alex Bennée, 2023/10/29
- [PATCH v2 17/19] semihosting: fix memleak at semihosting_arg_fallback,
Alex Bennée <=
- [PATCH v2 12/19] tests/docker: use debian-all-test-cross for mips, Alex Bennée, 2023/10/29
- [PATCH v2 16/19] gdbstub: Check if gdb_regs is NULL, Alex Bennée, 2023/10/29
- [PATCH v2 13/19] tests/docker: use debian-all-test-cross for riscv64, Alex Bennée, 2023/10/29
- [PATCH v2 15/19] tests/docker: upgrade debian-all-test-cross to bookworm, Alex Bennée, 2023/10/29
- [PATCH v2 19/19] contrib/plugins: Close file descriptor on error return, Alex Bennée, 2023/10/29
- [PATCH v2 18/19] plugins: Remove an extra parameter, Alex Bennée, 2023/10/29