From 65098b11f8aa28e328c225dcd39e3338bb005fdc Mon Sep 17 00:00:00 2001 From: Vincent Fu Date: Thu, 5 Sep 2024 14:35:30 -0400 Subject: [PATCH] iolog: add va_end on error Call va_end when we encounter an error trying to print sample fields. This was reported by Coverity: ** CID 509197: API usage errors (VARARGS) /iolog.c: 1025 in print_sample_fields() ________________________________________________________________________________________________________ *** CID 509197: API usage errors (VARARGS) /iolog.c: 1025 in print_sample_fields() 1019 int ret; 1020 1021 va_start(ap, fmt); 1022 ret = vsnprintf(*p, *left, fmt, ap); 1023 if (ret < 0 || ret >= *left) { 1024 log_err("sample file write failed: %d\n", ret); >>> CID 509197: API usage errors (VARARGS) >>> "va_end" was not called for "ap". 1025 return -1; 1026 } 1027 va_end(ap); 1028 1029 *p += ret; 1030 *left -= ret; Fixes: 3ec6b6da ("iolog: refactor flush_samples()") Signed-off-by: Vincent Fu --- iolog.c | 1 + 1 file changed, 1 insertion(+) diff --git a/iolog.c b/iolog.c index aadb0d052b..ef173b0929 100644 --- a/iolog.c +++ b/iolog.c @@ -1022,6 +1022,7 @@ static int print_sample_fields(char **p, size_t *left, const char *fmt, ...) { ret = vsnprintf(*p, *left, fmt, ap); if (ret < 0 || ret >= *left) { log_err("sample file write failed: %d\n", ret); + va_end(ap); return -1; } va_end(ap);