From: Peter Krempa Date: Mon, 9 Sep 2024 14:46:02 +0000 (+0200) Subject: virDomainDefParseBootInitOptions: Don't leak 'name' on failure X-Git-Url: http://xenbits.xensource.com/gitweb?a=commitdiff_plain;h=bc02cb95063aa1151a77c93f3dc177d7987202ba;p=libvirt.git virDomainDefParseBootInitOptions: Don't leak 'name' on failure 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 Reviewed-by: Pavel Hrdina --- 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 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;