From: Kirill Shchetiniuk <[email protected]>

Signed-off-by: Kirill Shchetiniuk <[email protected]>
---
 src/conf/domain_conf.c | 5 ++---
 src/conf/domain_conf.h | 1 +
 2 files changed, 3 insertions(+), 3 deletions(-)

diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c
index 02f55ade44..14fb82e296 100644
--- a/src/conf/domain_conf.c
+++ b/src/conf/domain_conf.c
@@ -3498,17 +3498,16 @@ virDomainHostdevDefNew(void)
 static virDomainTPMDef *
 virDomainTPMDefNew(virDomainXMLOption *xmlopt)
 {
-    virDomainTPMDef *def;
+    g_autoptr(virDomainTPMDef) def = NULL;
 
     def = g_new0(virDomainTPMDef, 1);
 
     if (xmlopt && xmlopt->privateData.tpmNew &&
         !(def->privateData = xmlopt->privateData.tpmNew())) {
-        VIR_FREE(def);
         return NULL;
     }
 
-    return def;
+    return g_steal_pointer(&def);
 }
 
 void virDomainTPMDefFree(virDomainTPMDef *def)
diff --git a/src/conf/domain_conf.h b/src/conf/domain_conf.h
index 185fc959aa..ec68776653 100644
--- a/src/conf/domain_conf.h
+++ b/src/conf/domain_conf.h
@@ -3812,6 +3812,7 @@ virDomainDeviceInfo *virDomainDeviceGetInfo(const 
virDomainDeviceDef *device);
 void virDomainDeviceSetData(virDomainDeviceDef *device,
                             void *devicedata);
 void virDomainTPMDefFree(virDomainTPMDef *def);
+G_DEFINE_AUTOPTR_CLEANUP_FUNC(virDomainTPMDef, virDomainTPMDefFree);
 
 typedef int (*virDomainDeviceInfoCallback)(virDomainDef *def,
                                            virDomainDeviceDef *dev,
-- 
2.49.0

Reply via email to