|
|
605e35 |
From 66e4ee795d21a30118f8503c966e9f9ae87db315 Mon Sep 17 00:00:00 2001
|
|
|
605e35 |
From: Xin Long <lucien.xin@gmail.com>
|
|
|
605e35 |
Date: Wed, 25 Jul 2018 17:39:33 +0800
|
|
|
605e35 |
Subject: [PATCH] Call va_end after va_copy in json_vsprintf
|
|
|
605e35 |
|
|
|
605e35 |
As said in man doc:
|
|
|
605e35 |
"Each invocation of va_copy() must be matched by a corresponding
|
|
|
605e35 |
invocation of va_end() in the same function."
|
|
|
605e35 |
|
|
|
605e35 |
va_copy may alloc memory in some system, it's necessay to free it by
|
|
|
605e35 |
va_end.
|
|
|
605e35 |
|
|
|
605e35 |
Fixes: efe6c7b3f2b3 ("Add json_sprintf and json_vsprintf")
|
|
|
605e35 |
Signed-off-by: Xin Long <lucien.xin@gmail.com>
|
|
|
605e35 |
---
|
|
|
605e35 |
src/value.c | 17 ++++++++++++-----
|
|
|
605e35 |
1 file changed, 12 insertions(+), 5 deletions(-)
|
|
|
605e35 |
|
|
|
605e35 |
diff --git a/src/value.c b/src/value.c
|
|
|
605e35 |
index 29a978c..861dce8 100644
|
|
|
605e35 |
--- a/src/value.c
|
|
|
605e35 |
+++ b/src/value.c
|
|
|
605e35 |
@@ -781,26 +781,33 @@ static json_t *json_string_copy(const json_t *string)
|
|
|
605e35 |
}
|
|
|
605e35 |
|
|
|
605e35 |
json_t *json_vsprintf(const char *fmt, va_list ap) {
|
|
|
605e35 |
+ json_t *json = NULL;
|
|
|
605e35 |
int length;
|
|
|
605e35 |
char *buf;
|
|
|
605e35 |
va_list aq;
|
|
|
605e35 |
va_copy(aq, ap);
|
|
|
605e35 |
|
|
|
605e35 |
length = vsnprintf(NULL, 0, fmt, ap);
|
|
|
605e35 |
- if (length == 0)
|
|
|
605e35 |
- return json_string("");
|
|
|
605e35 |
+ if (length == 0) {
|
|
|
605e35 |
+ json = json_string("");
|
|
|
605e35 |
+ goto out;
|
|
|
605e35 |
+ }
|
|
|
605e35 |
|
|
|
605e35 |
buf = jsonp_malloc(length + 1);
|
|
|
605e35 |
if (!buf)
|
|
|
605e35 |
- return NULL;
|
|
|
605e35 |
+ goto out;
|
|
|
605e35 |
|
|
|
605e35 |
vsnprintf(buf, length + 1, fmt, aq);
|
|
|
605e35 |
if (!utf8_check_string(buf, length)) {
|
|
|
605e35 |
jsonp_free(buf);
|
|
|
605e35 |
- return NULL;
|
|
|
605e35 |
+ goto out;
|
|
|
605e35 |
}
|
|
|
605e35 |
|
|
|
605e35 |
- return jsonp_stringn_nocheck_own(buf, length);
|
|
|
605e35 |
+ json = jsonp_stringn_nocheck_own(buf, length);
|
|
|
605e35 |
+
|
|
|
605e35 |
+out:
|
|
|
605e35 |
+ va_end(aq);
|
|
|
605e35 |
+ return json;
|
|
|
605e35 |
}
|
|
|
605e35 |
|
|
|
605e35 |
json_t *json_sprintf(const char *fmt, ...) {
|
|
|
605e35 |
--
|
|
|
605e35 |
2.1.0
|
|
|
605e35 |
|