hyperv: enable use of g_autoptr for the rest of the CIM/WMI classes

Signed-off-by: Matt Coleman <matt@datto.com>
Reviewed-by: Laine Stump <laine@redhat.com>
This commit is contained in:
Matt Coleman 2021-01-21 13:50:46 -05:00 committed by Laine Stump
parent e668d4a57d
commit a245dbdd4a
3 changed files with 11 additions and 7 deletions

View File

@ -98,6 +98,8 @@ class WmiClass:
typedef = "typedef struct _%s %s;\n" % (self.name, self.name) typedef = "typedef struct _%s %s;\n" % (self.name, self.name)
typedef += "typedef struct _%s_Data %s_Data;\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 return typedef
@ -308,6 +310,8 @@ def main():
classes_header.write(notice) classes_header.write(notice)
classes_source.write(notice) classes_source.write(notice)
classes_typedef.write("void hypervFreeObject(void *object);\n\n\n")
names = sorted(wmi_classes_by_name.keys()) names = sorted(wmi_classes_by_name.keys())
for name in names: for name in names:

View File

@ -1068,7 +1068,7 @@ hypervEnumAndPull(hypervPrivate *priv, hypervWqlQueryPtr wqlQuery,
void void
hypervFreeObject(hypervObject *object) hypervFreeObject(void *object)
{ {
hypervObject *next; hypervObject *next;
WsSerializerContextH serializerContext; WsSerializerContextH serializerContext;
@ -1076,15 +1076,15 @@ hypervFreeObject(hypervObject *object)
if (object == NULL) if (object == NULL)
return; return;
serializerContext = wsmc_get_serialization_context(object->priv->client); serializerContext = wsmc_get_serialization_context(((hypervObject *)object)->priv->client);
while (object != NULL) { 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, if (ws_serializer_free_mem(serializerContext, ((hypervObject *)object)->data,
object->info->serializerInfo) < 0) { ((hypervObject *)object)->info->serializerInfo) < 0) {
VIR_ERROR(_("Could not free deserialized data")); VIR_ERROR(_("Could not free deserialized data"));
} }

View File

@ -63,7 +63,7 @@ struct _hypervWqlQuery {
int hypervEnumAndPull(hypervPrivate *priv, hypervWqlQueryPtr wqlQuery, int hypervEnumAndPull(hypervPrivate *priv, hypervWqlQueryPtr wqlQuery,
hypervObject **list); hypervObject **list);
void hypervFreeObject(hypervObject *object); void hypervFreeObject(void *object);
G_DEFINE_AUTOPTR_CLEANUP_FUNC(hypervObject, hypervFreeObject); G_DEFINE_AUTOPTR_CLEANUP_FUNC(hypervObject, hypervFreeObject);