From: Antonio Borneo Date: Mon, 4 Jan 2021 18:24:21 +0000 (+0100) Subject: target: fix memory leak on multiple '-gdb-port' flag X-Git-Tag: v0.11.0-rc2~19 X-Git-Url: https://review.openocd.org/gitweb?p=openocd.git;a=commitdiff_plain;h=c1270bcb38477a0c8a8be32921fccda61f9c06c7 target: fix memory leak on multiple '-gdb-port' flag In the odd case of multiple flags '-gdb-port' during 'target create' or following 'configure', the new strdup()'ed value will replace the old one without freeing it. Free the old value (if it exists) before replacing it. Change-Id: I1673346613ce7023880046e3a9ba473e75f18b8a Signed-off-by: Antonio Borneo Reviewed-on: http://openocd.zylin.com/6005 Tested-by: jenkins --- diff --git a/src/target/target.c b/src/target/target.c index 3c1a6338e9..c752844b04 100644 --- a/src/target/target.c +++ b/src/target/target.c @@ -5123,6 +5123,7 @@ no_params: e = Jim_GetOpt_String(goi, &s, NULL); if (e != JIM_OK) return e; + free(target->gdb_port_override); target->gdb_port_override = strdup(s); } else { if (goi->argc != 0)