From a245dbdd4a319af9fd03d08699959397084827ea Mon Sep 17 00:00:00 2001 From: Matt Coleman Date: Thu, 21 Jan 2021 13:50:46 -0500 Subject: [PATCH] hyperv: enable use of g_autoptr for the rest of the CIM/WMI classes Signed-off-by: Matt Coleman Reviewed-by: Laine Stump --- scripts/hyperv_wmi_generator.py | 4 ++++ src/hyperv/hyperv_wmi.c | 12 ++++++------ src/hyperv/hyperv_wmi.h | 2 +- 3 files changed, 11 insertions(+), 7 deletions(-) diff --git a/scripts/hyperv_wmi_generator.py b/scripts/hyperv_wmi_generator.py index e5e961d2db..f26558cb56 100755 --- a/scripts/hyperv_wmi_generator.py +++ b/scripts/hyperv_wmi_generator.py @@ -98,6 +98,8 @@ class WmiClass: typedef = "typedef struct _%s %s;\n" % (self.name, self.name) typedef += "typedef struct _%s_Data %s_Data;\n" % (self.name, self.name) + typedef += "G_DEFINE_AUTOPTR_CLEANUP_FUNC(%s, hypervFreeObject);\n" % self.name + typedef += "\n" return typedef @@ -308,6 +310,8 @@ def main(): classes_header.write(notice) classes_source.write(notice) + classes_typedef.write("void hypervFreeObject(void *object);\n\n\n") + names = sorted(wmi_classes_by_name.keys()) for name in names: diff --git a/src/hyperv/hyperv_wmi.c b/src/hyperv/hyperv_wmi.c index 2a4377a12f..0a9d4bf4fd 100644 --- a/src/hyperv/hyperv_wmi.c +++ b/src/hyperv/hyperv_wmi.c @@ -1068,7 +1068,7 @@ hypervEnumAndPull(hypervPrivate *priv, hypervWqlQueryPtr wqlQuery, void -hypervFreeObject(hypervObject *object) +hypervFreeObject(void *object) { hypervObject *next; WsSerializerContextH serializerContext; @@ -1076,15 +1076,15 @@ hypervFreeObject(hypervObject *object) if (object == NULL) return; - serializerContext = wsmc_get_serialization_context(object->priv->client); + serializerContext = wsmc_get_serialization_context(((hypervObject *)object)->priv->client); while (object != NULL) { - next = object->next; + next = ((hypervObject *)object)->next; - object->priv = NULL; + ((hypervObject *)object)->priv = NULL; - if (ws_serializer_free_mem(serializerContext, object->data, - object->info->serializerInfo) < 0) { + if (ws_serializer_free_mem(serializerContext, ((hypervObject *)object)->data, + ((hypervObject *)object)->info->serializerInfo) < 0) { VIR_ERROR(_("Could not free deserialized data")); } diff --git a/src/hyperv/hyperv_wmi.h b/src/hyperv/hyperv_wmi.h index c9b2728df3..f09948895e 100644 --- a/src/hyperv/hyperv_wmi.h +++ b/src/hyperv/hyperv_wmi.h @@ -63,7 +63,7 @@ struct _hypervWqlQuery { int hypervEnumAndPull(hypervPrivate *priv, hypervWqlQueryPtr wqlQuery, hypervObject **list); -void hypervFreeObject(hypervObject *object); +void hypervFreeObject(void *object); G_DEFINE_AUTOPTR_CLEANUP_FUNC(hypervObject, hypervFreeObject);