acrn-hypervisor/tools/acrn-crashlog/common/log_sys.c
Tianhua Sun c0cb9c509f 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: #3406
Signed-off-by: Tianhua Sun <tianhuax.s.sun@intel.com>
Acked-by: Gang Chen <gang.c.chen@intel.com>
2019-07-18 15:18:29 +08:00

43 lines
690 B
C

/*
* Copyright (C) <2018> Intel Corporation
* SPDX-License-Identifier: BSD-3-Clause
*/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <stdarg.h>
#include "log_sys.h"
void debug_log(const int level, const char *func, const int line, ...)
{
va_list args;
char *fmt;
char *head;
char *msg;
if (level > LOG_LEVEL)
return;
va_start(args, line);
fmt = va_arg(args, char *);
if (!fmt) {
va_end(args);
return;
}
if (vasprintf(&msg, fmt, args) == -1) {
va_end(args);
return;
}
va_end(args);
if (asprintf(&head, "<%-20s%5d>: ", func, line) == -1) {
free(msg);
return;
}
sd_journal_print(level, "%s%s", head, msg);
free(msg);
free(head);
}