From c76197ddbbd0c29adc2bceff2ee9f740f71d134d Mon Sep 17 00:00:00 2001
From: Daiki Ueno <dueno@redhat.com>
Date: Tue, 16 Oct 2018 18:06:56 +0200
Subject: [PATCH 04/36] build: Call va_end() always when leaving the function

---
 common/attrs.c  | 4 +++-
 common/compat.c | 5 ++++-
 common/path.c   | 5 ++++-
 trust/parser.c  | 4 +++-
 4 files changed, 14 insertions(+), 4 deletions(-)

diff --git a/common/attrs.c b/common/attrs.c
index aa91891..a387a66 100644
--- a/common/attrs.c
+++ b/common/attrs.c
@@ -538,8 +538,10 @@ buffer_append_printf (p11_buffer *buffer,
 	va_list va;
 
 	va_start (va, format);
-	if (vasprintf (&string, format, va) < 0)
+	if (vasprintf (&string, format, va) < 0) {
+		va_end (va);
 		return_if_reached ();
+	}
 	va_end (va);
 
 	p11_buffer_add (buffer, string, -1);
diff --git a/common/compat.c b/common/compat.c
index 5a9702d..48614fa 100644
--- a/common/compat.c
+++ b/common/compat.c
@@ -525,7 +525,10 @@ strconcat (const char *first,
 	for (arg = first; arg; arg = va_arg (va, const char*)) {
 		size_t old_length = length;
 		length += strlen (arg);
-		return_val_if_fail (length >= old_length, NULL);
+		if (length < old_length) {
+			va_end (va);
+			return_val_if_reached (NULL);
+		}
 	}
 
 	va_end (va);
diff --git a/common/path.c b/common/path.c
index 5cf0e1a..17a6230 100644
--- a/common/path.c
+++ b/common/path.c
@@ -218,7 +218,10 @@ p11_path_build (const char *path,
 	while (path != NULL) {
 		size_t old_len = len;
 		len += strlen (path) + 1;
-		return_val_if_fail (len >= old_len, NULL);
+		if (len < old_len) {
+			va_end (va);
+			return_val_if_reached (NULL);
+		}
 		path = va_arg (va, const char *);
 	}
 	va_end (va);
diff --git a/trust/parser.c b/trust/parser.c
index f92cdc9..e912c3a 100644
--- a/trust/parser.c
+++ b/trust/parser.c
@@ -697,8 +697,10 @@ p11_parser_formats (p11_parser *parser,
 		func = va_arg (va, parser_func);
 		if (func == NULL)
 			break;
-		if (!p11_array_push (formats, func))
+		if (!p11_array_push (formats, func)) {
+			va_end (va);
 			return_if_reached ();
+		}
 	}
 	va_end (va);
 
-- 
2.19.1

