Skip to content

Commit

Permalink
iolog: add va_end on error
Browse files Browse the repository at this point in the history
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: 3ec6b6d ("iolog: refactor flush_samples()")
Signed-off-by: Vincent Fu <vincent.fu@samsung.com>
  • Loading branch information
vincentkfu committed Sep 5, 2024
1 parent 20d0ba8 commit 65098b1
Showing 1 changed file with 1 addition and 0 deletions.
1 change: 1 addition & 0 deletions iolog.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down

0 comments on commit 65098b1

Please sign in to comment.