]> xenbits.xensource.com Git - libvirt.git/commitdiff
virDomainVideoDriverDefParseXML: Fix use of uninitialized variable
authorPeter Krempa <pkrempa@redhat.com>
Wed, 5 May 2021 12:08:29 +0000 (14:08 +0200)
committerPeter Krempa <pkrempa@redhat.com>
Wed, 5 May 2021 12:08:29 +0000 (14:08 +0200)
Commit fc7e1b2f03cfe2a5f3fce737390548505382d8ed which refactored the
video driver parse helper introduced a use of uninitialized variable,
which caused test failure at least when compiled with clang.

Pass 'def->vgaconf' directly to virXMLPropEnum. 'def' needs to be
converted to use g_autofree to handle error scenarios.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
src/conf/domain_conf.c

index 64f525fc089f937dfb2cf58330d5f7c9a8401977..d5d8bd0a01226b59599a21da403e4dbf8998c127 100644 (file)
@@ -14313,8 +14313,7 @@ static virDomainVideoDriverDef *
 virDomainVideoDriverDefParseXML(xmlNodePtr node,
                                 xmlXPathContextPtr ctxt)
 {
-    virDomainVideoDriverDef *def;
-    unsigned int val;
+    g_autofree virDomainVideoDriverDef *def = NULL;
     xmlNodePtr driver = NULL;
     VIR_XPATH_NODE_AUTORESTORE(ctxt)
 
@@ -14323,15 +14322,14 @@ virDomainVideoDriverDefParseXML(xmlNodePtr node,
     if (!(driver = virXPathNode("./driver", ctxt)))
         return NULL;
 
+    def = g_new0(virDomainVideoDriverDef, 1);
+
     if (virXMLPropEnum(driver, "vgaconf",
                        virDomainVideoVGAConfTypeFromString,
-                       VIR_XML_PROP_NONZERO, &val) < 0)
+                       VIR_XML_PROP_NONZERO, &def->vgaconf) < 0)
         return NULL;
 
-    def = g_new0(virDomainVideoDriverDef, 1);
-    def->vgaconf = val;
-
-    return def;
+    return g_steal_pointer(&def);
 }
 
 static virDomainVideoDef *