aboutsummaryrefslogtreecommitdiff
path: root/sim/common/sim-options.c
diff options
context:
space:
mode:
authorMike Frysinger <vapier@gentoo.org>2011-05-27 18:05:16 +0000
committerMike Frysinger <vapier@gentoo.org>2011-05-27 18:05:16 +0000
commit440db5755211bd29af95c374882c109ede000b54 (patch)
treee738878e775cd0cd3cbfbc5b758335696056cb92 /sim/common/sim-options.c
parent432b4d03ad0f23970315e9f9dec080ab4a9ab94b (diff)
downloadgdb-440db5755211bd29af95c374882c109ede000b54.zip
gdb-440db5755211bd29af95c374882c109ede000b54.tar.gz
gdb-440db5755211bd29af95c374882c109ede000b54.tar.bz2
sim: fix minor --sysroot mem leak
The current --sysroot parsing attempts to keep from leaking memory by treating the empty string specially (sine this is the initial value), but it ends up leaking memory when the arg is an empty string. So if someone uses --sysroot "", the old value is leaked, as is the new one. Signed-off-by: Mike Frysinger <vapier@gentoo.org>
Diffstat (limited to 'sim/common/sim-options.c')
-rw-r--r--sim/common/sim-options.c10
1 files changed, 7 insertions, 3 deletions
diff --git a/sim/common/sim-options.c b/sim/common/sim-options.c
index ddab83d..1a0c541 100644
--- a/sim/common/sim-options.c
+++ b/sim/common/sim-options.c
@@ -458,10 +458,14 @@ standard_option_handler (SIM_DESC sd, sim_cpu *cpu, int opt,
case OPTION_SYSROOT:
/* Don't leak memory in the odd event that there's lots of
- --sysroot=... options. */
- if (simulator_sysroot[0] != '\0' && arg[0] != '\0')
+ --sysroot=... options. We treat "" specially since this
+ is the statically initialized value and cannot free it. */
+ if (simulator_sysroot[0] != '\0')
free (simulator_sysroot);
- simulator_sysroot = xstrdup (arg);
+ if (arg[0] != '\0')
+ simulator_sysroot = xstrdup (arg);
+ else
+ simulator_sysroot = "";
break;
}