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(a)redhat.com>
---
src/conf/domain_conf.c | 5 +++--
1 file changed, 3 insertions(+), 2 deletions(-)
diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c
index a263612ef7..d72870d87d 100644
--- a/src/conf/domain_conf.c
+++ b/src/conf/domain_conf.c
@@ -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;
--
2.46.0