Blob Blame History Raw
From 25ceaef5ff5e392dace991db3e737dbdb50a6bba Mon Sep 17 00:00:00 2001
Message-Id: <25ceaef5ff5e392dace991db3e737dbdb50a6bba@dist-git>
From: Sukrit Bhatnagar <skrtbhtngr@gmail.com>
Date: Fri, 21 Jun 2019 09:26:02 +0200
Subject: [PATCH] util: json: define cleanup function using
 VIR_DEFINE_AUTOPTR_FUNC
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

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 <skrtbhtngr@gmail.com>
Reviewed-by: Erik Skultety <eskultet@redhat.com>
(cherry picked from commit b5b5cdd69ca1c954635f9f6dda05d6b15b01cc8a)

https://bugzilla.redhat.com/show_bug.cgi?id=1697627

Signed-off-by: Jiri Denemark <jdenemar@redhat.com>
Message-Id: <4dd72d7d93725d77a2bd89fbd890fe3d774f29d2.1561068591.git.jdenemar@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
---
 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 <config.h>
 
 #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 <stdarg.h>
 
@@ -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_ */
-- 
2.22.0