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 <borneo.antonio@gmail.com>
Reviewed-on: http://openocd.zylin.com/6005
Tested-by: jenkins
This commit is contained in:
Antonio Borneo 2021-01-04 19:24:21 +01:00
parent e22198c152
commit c1270bcb38
1 changed files with 1 additions and 0 deletions

View File

@ -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)