From 86e51d68f91af66ec6ee1d55358b2e0601161ecb Mon Sep 17 00:00:00 2001 From: Peter Krempa Date: Thu, 16 Mar 2017 10:19:32 +0100 Subject: [PATCH] util: json: Make function to free JSON values in virHash universal Move the helper that frees JSON entries put into hash tables into the JSON module so that it does not have to be reimplemented. --- src/libvirt_private.syms | 1 + src/qemu/qemu_monitor_json.c | 10 +--------- src/util/virjson.c | 8 ++++++++ src/util/virjson.h | 1 + 4 files changed, 11 insertions(+), 9 deletions(-) diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms index ead2149dd0..744779ad22 100644 --- a/src/libvirt_private.syms +++ b/src/libvirt_private.syms @@ -1835,6 +1835,7 @@ virJSONValueGetNumberLong; virJSONValueGetNumberUint; virJSONValueGetNumberUlong; virJSONValueGetString; +virJSONValueHashFree; virJSONValueIsArray; virJSONValueIsNull; virJSONValueNewArray; diff --git a/src/qemu/qemu_monitor_json.c b/src/qemu/qemu_monitor_json.c index 35ee72cf18..e68c31ef45 100644 --- a/src/qemu/qemu_monitor_json.c +++ b/src/qemu/qemu_monitor_json.c @@ -7488,14 +7488,6 @@ qemuMonitorJSONFillQMPSchema(size_t pos ATTRIBUTE_UNUSED, } -static void -qemuMonitorJSONFreeSchemaEntry(void *opaque, - const void *name ATTRIBUTE_UNUSED) -{ - virJSONValueFree(opaque); -} - - virHashTablePtr qemuMonitorJSONQueryQMPSchema(qemuMonitorPtr mon) { @@ -7516,7 +7508,7 @@ qemuMonitorJSONQueryQMPSchema(qemuMonitorPtr mon) arr = virJSONValueObjectGet(reply, "return"); - if (!(schema = virHashCreate(512, qemuMonitorJSONFreeSchemaEntry))) + if (!(schema = virHashCreate(512, virJSONValueHashFree))) goto cleanup; if (virJSONValueArrayForeachSteal(arr, qemuMonitorJSONFillQMPSchema, diff --git a/src/util/virjson.c b/src/util/virjson.c index c907b5ded1..b49b29b0fb 100644 --- a/src/util/virjson.c +++ b/src/util/virjson.c @@ -376,6 +376,14 @@ virJSONValueFree(virJSONValuePtr value) } +void +virJSONValueHashFree(void *opaque, + const void *name ATTRIBUTE_UNUSED) +{ + virJSONValueFree(opaque); +} + + virJSONValuePtr virJSONValueNewString(const char *data) { diff --git a/src/util/virjson.h b/src/util/virjson.h index 5e32cb9a41..14b74c0617 100644 --- a/src/util/virjson.h +++ b/src/util/virjson.h @@ -81,6 +81,7 @@ struct _virJSONValue { }; void virJSONValueFree(virJSONValuePtr value); +void virJSONValueHashFree(void *opaque, const void *name); int virJSONValueObjectCreate(virJSONValuePtr *obj, ...) ATTRIBUTE_NONNULL(1) ATTRIBUTE_SENTINEL;