sim: sim_do_commandf: fix call to va_end [PR sim/19273]

Make sure we call va_end even in the error case.
This commit is contained in:
Mike Frysinger 2015-11-21 23:10:04 -08:00
parent 7c125e3b10
commit 2561d5808a
2 changed files with 13 additions and 2 deletions

View File

@ -1,3 +1,9 @@
2015-11-21 Mike Frysinger <vapier@gentoo.org>
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 <vapier@gentoo.org>
* sim-types.h (SIM_PRI_TB): Define.

View File

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