提交 4817687a 编写于 作者: M Michal Privoznik

conf: Rework virDomainSEVDefParseXML()

Firstly, this function changes node for relative XPaths but
doesn't restore the original one in case VIR_ALLOC(def) fails.
Secondly, @type is leaked. Thirdly, dh-cert and session
attributes are strdup()-ed needlessly, virXPathString already
does that so we can use the retval immediately.
Signed-off-by: NMichal Privoznik <mprivozn@redhat.com>
Reviewed-by: NJán Tomko <jtomko@redhat.com>
上级 84e4046c
...@@ -15849,17 +15849,16 @@ static virDomainSevDefPtr ...@@ -15849,17 +15849,16 @@ static virDomainSevDefPtr
virDomainSEVDefParseXML(xmlNodePtr sevNode, virDomainSEVDefParseXML(xmlNodePtr sevNode,
xmlXPathContextPtr ctxt) xmlXPathContextPtr ctxt)
{ {
char *tmp = NULL;
char *type = NULL; char *type = NULL;
xmlNodePtr save = ctxt->node; xmlNodePtr save = ctxt->node;
virDomainSevDefPtr def; virDomainSevDefPtr def;
unsigned long policy; unsigned long policy;
ctxt->node = sevNode;
if (VIR_ALLOC(def) < 0) if (VIR_ALLOC(def) < 0)
return NULL; return NULL;
ctxt->node = sevNode;
if (!(type = virXMLPropString(sevNode, "type"))) { if (!(type = virXMLPropString(sevNode, "type"))) {
virReportError(VIR_ERR_XML_ERROR, "%s", virReportError(VIR_ERR_XML_ERROR, "%s",
_("missing launch security type")); _("missing launch security type"));
...@@ -15899,29 +15898,18 @@ virDomainSEVDefParseXML(xmlNodePtr sevNode, ...@@ -15899,29 +15898,18 @@ virDomainSEVDefParseXML(xmlNodePtr sevNode,
} }
def->policy = policy; def->policy = policy;
def->dh_cert = virXPathString("string(./dhCert)", ctxt);
def->session = virXPathString("string(./session)", ctxt);
if ((tmp = virXPathString("string(./dhCert)", ctxt))) { cleanup:
if (VIR_STRDUP(def->dh_cert, tmp) < 0) VIR_FREE(type);
goto error;
VIR_FREE(tmp);
}
if ((tmp = virXPathString("string(./session)", ctxt))) {
if (VIR_STRDUP(def->session, tmp) < 0)
goto error;
VIR_FREE(tmp);
}
ctxt->node = save; ctxt->node = save;
return def; return def;
error: error:
VIR_FREE(tmp);
virDomainSEVDefFree(def); virDomainSEVDefFree(def);
ctxt->node = save; def = NULL;
return NULL; goto cleanup;
} }
static virDomainMemoryDefPtr static virDomainMemoryDefPtr
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册