From e0825685ecf76988683488390096890114478aab Mon Sep 17 00:00:00 2001 From: Denis Pronin Date: Sun, 10 Apr 2022 15:41:47 +0300 Subject: [PATCH] fixed bunch of memory leaks in json constructor fixed memory leak produced by not freed string given by 'strdup' in 'json_object_add_value_string' function Signed-off-by: Denis Pronin --- json.h | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/json.h b/json.h index d9824263..66bb06b1 100644 --- a/json.h +++ b/json.h @@ -81,8 +81,13 @@ static inline int json_object_add_value_string(struct json_object *obj, struct json_value arg = { .type = JSON_TYPE_STRING, }; + union { + const char *a; + char *b; + } string; - arg.string = strdup(val ? : ""); + string.a = val ? val : ""; + arg.string = string.b; return json_object_add_value_type(obj, name, &arg); } -- 2.25.1