From b5b5cdd69ca1c954635f9f6dda05d6b15b01cc8a Mon Sep 17 00:00:00 2001 From: Sukrit Bhatnagar Date: Fri, 13 Jul 2018 23:24:56 +0530 Subject: [PATCH] util: json: define cleanup function using VIR_DEFINE_AUTOPTR_FUNC Using the new VIR_DEFINE_AUTOPTR_FUNC macro defined in src/util/viralloc.h, define a new wrapper around an existing cleanup function which will be called when a variable declared with VIR_AUTOPTR macro goes out of scope. Also, drop the redundant viralloc.h include, since that has moved from the source module into the header. When a variable of type virJSONValuePtr is declared using VIR_AUTOPTR, the function virJSONValueFree will be run automatically on it when it goes out of scope. Signed-off-by: Sukrit Bhatnagar Reviewed-by: Erik Skultety --- src/util/virjson.c | 1 - src/util/virjson.h | 3 +++ 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/src/util/virjson.c b/src/util/virjson.c index 0559d40b64..92f3994e92 100644 --- a/src/util/virjson.c +++ b/src/util/virjson.c @@ -24,7 +24,6 @@ #include #include "virjson.h" -#include "viralloc.h" #include "virerror.h" #include "virlog.h" #include "virstring.h" diff --git a/src/util/virjson.h b/src/util/virjson.h index e4a82bdbc8..75f7f17b44 100644 --- a/src/util/virjson.h +++ b/src/util/virjson.h @@ -26,6 +26,7 @@ # include "internal.h" # include "virbitmap.h" +# include "viralloc.h" # include @@ -156,4 +157,6 @@ char *virJSONStringReformat(const char *jsonstr, bool pretty); virJSONValuePtr virJSONValueObjectDeflatten(virJSONValuePtr json); +VIR_DEFINE_AUTOPTR_FUNC(virJSONValue, virJSONValueFree) + #endif /* __VIR_JSON_H_ */