]> xenbits.xensource.com Git - libvirt.git/commitdiff
virDomainDefParseBootInitOptions: Don't leak 'name' on failure
authorPeter Krempa <pkrempa@redhat.com>
Mon, 9 Sep 2024 14:46:02 +0000 (16:46 +0200)
committerPavel Hrdina <phrdina@redhat.com>
Tue, 10 Sep 2024 12:24:48 +0000 (14:24 +0200)
One of the failure paths skips code which would assign the string from
the temporary variable to the parsed struct, thus leaking it on failure.

Closes: https://gitlab.com/libvirt/libvirt/-/issues/672
Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Pavel Hrdina <phrdina@redhat.com>
src/conf/domain_conf.c

index a263612ef7aed6735b7825d25f65a4ce44b1f67e..d72870d87d5d3a3dd0ba8576b85e371cac54a8f4 100644 (file)
@@ -17518,7 +17518,6 @@ static int
 virDomainDefParseBootInitOptions(virDomainDef *def,
                                  xmlXPathContextPtr ctxt)
 {
-    char *name = NULL;
     size_t i;
     int n;
     g_autofree xmlNodePtr *nodes = NULL;
@@ -17550,6 +17549,8 @@ virDomainDefParseBootInitOptions(virDomainDef *def,
 
     def->os.initenv = g_new0(virDomainOSEnv *, n + 1);
     for (i = 0; i < n; i++) {
+        g_autofree char *name = NULL;
+
         if (!(name = virXMLPropString(nodes[i], "name"))) {
             virReportError(VIR_ERR_XML_ERROR, "%s",
                            _("No name supplied for <initenv> element"));
@@ -17565,7 +17566,7 @@ virDomainDefParseBootInitOptions(virDomainDef *def,
         }
 
         def->os.initenv[i] = g_new0(virDomainOSEnv, 1);
-        def->os.initenv[i]->name = name;
+        def->os.initenv[i]->name = g_steal_pointer(&name);
         def->os.initenv[i]->value = g_strdup((const char *)nodes[i]->children->content);
     }
     def->os.initenv[n] = NULL;