From: Mike Frysinger Date: Sun, 22 Nov 2015 07:10:04 +0000 (-0800) Subject: sim: sim_do_commandf: fix call to va_end [PR sim/19273] X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=2561d5808a330240a28841e8b3ce706a65ed31c9;p=binutils-gdb.git sim: sim_do_commandf: fix call to va_end [PR sim/19273] Make sure we call va_end even in the error case. --- diff --git a/sim/common/ChangeLog b/sim/common/ChangeLog index 464fd80e1de..1b219950e62 100644 --- a/sim/common/ChangeLog +++ b/sim/common/ChangeLog @@ -1,3 +1,9 @@ +2015-11-21 Mike Frysinger + + PR sim/19273 + * sim-utils.c (sim_do_commandf): Declare ret. Call va_start, + vasprintf, and va_end together. Check ret after va_end call. + 2015-11-21 Mike Frysinger * sim-types.h (SIM_PRI_TB): Define. diff --git a/sim/common/sim-utils.c b/sim/common/sim-utils.c index 63d532df505..c6f96a8a07f 100644 --- a/sim/common/sim-utils.c +++ b/sim/common/sim-utils.c @@ -328,15 +328,20 @@ sim_do_commandf (SIM_DESC sd, { va_list ap; char *buf; + int ret; + va_start (ap, fmt); - if (vasprintf (&buf, fmt, ap) < 0) + ret = vasprintf (&buf, fmt, ap); + va_end (ap); + + if (ret < 0) { sim_io_eprintf (sd, "%s: asprintf failed for `%s'\n", STATE_MY_NAME (sd), fmt); return; } + sim_do_command (sd, buf); - va_end (ap); free (buf); }