[libvirt PATCH] conf: use correct free function for virDomainDeviceDef

Ján Tomko posted 1 patch 3 weeks ago
Test syntax-check failed
Patches applied successfully (tree, apply log)
git fetch https://github.com/patchew-project/libvirt tags/patchew/be8838a8032ccf29ec659490ca40aabde47522e4.1580862362.git.jtomko@redhat.com
src/conf/domain_conf.c | 2 +-
src/conf/domain_conf.h | 1 +
2 files changed, 2 insertions(+), 1 deletion(-)

[libvirt PATCH] conf: use correct free function for virDomainDeviceDef

Posted by Ján Tomko 3 weeks ago
Simple g_autofree is not enough if we put allocated
data into the device structure.

Define the AUTOPTR_CLEANUP function and use it here.

Signed-off-by: Ján Tomko <jtomko@redhat.com>
Reported-by: Xu Yandong <xuyandong2@huawei.com>
---
 src/conf/domain_conf.c | 2 +-
 src/conf/domain_conf.h | 1 +
 2 files changed, 2 insertions(+), 1 deletion(-)

diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c
index c95bd34fb5..c3214dc4f3 100644
--- a/src/conf/domain_conf.c
+++ b/src/conf/domain_conf.c
@@ -16516,7 +16516,7 @@ virDomainDeviceDefParse(const char *xmlStr,
     g_autoptr(xmlDoc) xml = NULL;
     xmlNodePtr node;
     g_autoptr(xmlXPathContext) ctxt = NULL;
-    g_autofree virDomainDeviceDefPtr dev = NULL;
+    g_autoptr(virDomainDeviceDef) dev = NULL;
 
     if (!(xml = virXMLParseStringCtxt(xmlStr, _("(device_definition)"), &ctxt)))
         return NULL;
diff --git a/src/conf/domain_conf.h b/src/conf/domain_conf.h
index e144f3aad3..c3acb29e6f 100644
--- a/src/conf/domain_conf.h
+++ b/src/conf/domain_conf.h
@@ -2916,6 +2916,7 @@ void virDomainRedirdevDefFree(virDomainRedirdevDefPtr def);
 void virDomainRedirFilterDefFree(virDomainRedirFilterDefPtr def);
 void virDomainShmemDefFree(virDomainShmemDefPtr def);
 void virDomainDeviceDefFree(virDomainDeviceDefPtr def);
+G_DEFINE_AUTOPTR_CLEANUP_FUNC(virDomainDeviceDef, virDomainDeviceDefFree);
 virDomainDeviceDefPtr virDomainDeviceDefCopy(virDomainDeviceDefPtr src,
                                              const virDomainDef *def,
                                              virDomainXMLOptionPtr xmlopt,
-- 
2.21.0

Re: [libvirt PATCH] conf: use correct free function for virDomainDeviceDef

Posted by Peter Krempa 3 weeks ago
On Wed, Feb 05, 2020 at 01:26:11 +0100, Ján Tomko wrote:
> Simple g_autofree is not enough if we put allocated
> data into the device structure.
> 
> Define the AUTOPTR_CLEANUP function and use it here.
> 
> Signed-off-by: Ján Tomko <jtomko@redhat.com>
> Reported-by: Xu Yandong <xuyandong2@huawei.com>

Ah, so this bug was actually introduced when adding the post parse and
validation callbacks, because otherwise it doesn't set anything in the
struct.

> ---
>  src/conf/domain_conf.c | 2 +-
>  src/conf/domain_conf.h | 1 +
>  2 files changed, 2 insertions(+), 1 deletion(-)

Reviewed-by: Peter Krempa <pkrempa@redhat.com>