tools: fix variable argument list read without ending with va_end

va_end() was not getting called under certain condition
after the va_start() function call taking the va_list

Tracked-On: #3396
Signed-off-by: Tianhua Sun <tianhuax.s.sun@intel.com>
Acked-by: Gang Chen <gang.c.chen@intel.com>
This commit is contained in:
Tianhua Sun 2019-07-11 09:20:01 +08:00 committed by wenlingz
parent bc90db46fc
commit 1394758d69
2 changed files with 7 additions and 3 deletions

View File

@ -21,10 +21,14 @@ void debug_log(const int level, const char *func, const int line, ...)
va_start(args, line); va_start(args, line);
fmt = va_arg(args, char *); fmt = va_arg(args, char *);
if (!fmt) if (!fmt) {
va_end(args);
return; return;
if (vasprintf(&msg, fmt, args) == -1) }
if (vasprintf(&msg, fmt, args) == -1) {
va_end(args);
return; return;
}
va_end(args); va_end(args);
if (asprintf(&head, "<%-20s%5d>: ", func, line) == -1) { if (asprintf(&head, "<%-20s%5d>: ", func, line) == -1) {

View File

@ -36,11 +36,11 @@ static void loginfo(int fd, const char *fmt, ...)
va_start(ap, fmt); va_start(ap, fmt);
len = vasprintf(&buf, fmt, ap); len = vasprintf(&buf, fmt, ap);
va_end(ap);
if (len == -1) { if (len == -1) {
LOGE("write to buf failed\n"); LOGE("write to buf failed\n");
return; return;
} }
va_end(ap);
ret = write(fd, buf, len); ret = write(fd, buf, len);
if (ret != len) { if (ret != len) {