mirror of
https://gitlab.com/libvirt/libvirt.git
synced 2024-12-22 05:35:25 +00:00
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 <pkrempa@redhat.com> Reviewed-by: Pavel Hrdina <phrdina@redhat.com>
This commit is contained in:
parent
2feeefc0b4
commit
bc02cb9506
@ -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;
|
||||
|
Loading…
Reference in New Issue
Block a user