mirror of https://gitee.com/openkylin/libvirt.git
secretXMLParseNode: Clean up freeing of memory
Use one variable per extracted property instead of reusing strings and drop needless VIR_FREE calls. Signed-off-by: Peter Krempa <pkrempa@redhat.com> Reviewed-by: Ján Tomko <jtomko@redhat.com>
This commit is contained in:
parent
a177c56ddd
commit
f07f1c479a
|
@ -131,7 +131,8 @@ secretXMLParseNode(xmlDocPtr xml, xmlNodePtr root)
|
||||||
{
|
{
|
||||||
g_autoptr(xmlXPathContext) ctxt = NULL;
|
g_autoptr(xmlXPathContext) ctxt = NULL;
|
||||||
g_autoptr(virSecretDef) def = NULL;
|
g_autoptr(virSecretDef) def = NULL;
|
||||||
g_autofree char *prop = NULL;
|
g_autofree char *ephemeralstr = NULL;
|
||||||
|
g_autofree char *privatestr = NULL;
|
||||||
g_autofree char *uuidstr = NULL;
|
g_autofree char *uuidstr = NULL;
|
||||||
|
|
||||||
if (!virXMLNodeNameEqual(root, "secret")) {
|
if (!virXMLNodeNameEqual(root, "secret")) {
|
||||||
|
@ -149,24 +150,20 @@ secretXMLParseNode(xmlDocPtr xml, xmlNodePtr root)
|
||||||
|
|
||||||
def = g_new0(virSecretDef, 1);
|
def = g_new0(virSecretDef, 1);
|
||||||
|
|
||||||
prop = virXPathString("string(./@ephemeral)", ctxt);
|
if ((ephemeralstr = virXPathString("string(./@ephemeral)", ctxt))) {
|
||||||
if (prop != NULL) {
|
if (virStringParseYesNo(ephemeralstr, &def->isephemeral) < 0) {
|
||||||
if (virStringParseYesNo(prop, &def->isephemeral) < 0) {
|
|
||||||
virReportError(VIR_ERR_XML_ERROR, "%s",
|
virReportError(VIR_ERR_XML_ERROR, "%s",
|
||||||
_("invalid value of 'ephemeral'"));
|
_("invalid value of 'ephemeral'"));
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
VIR_FREE(prop);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
prop = virXPathString("string(./@private)", ctxt);
|
if ((privatestr = virXPathString("string(./@private)", ctxt))) {
|
||||||
if (prop != NULL) {
|
if (virStringParseYesNo(privatestr, &def->isprivate) < 0) {
|
||||||
if (virStringParseYesNo(prop, &def->isprivate) < 0) {
|
|
||||||
virReportError(VIR_ERR_XML_ERROR, "%s",
|
virReportError(VIR_ERR_XML_ERROR, "%s",
|
||||||
_("invalid value of 'private'"));
|
_("invalid value of 'private'"));
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
VIR_FREE(prop);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
uuidstr = virXPathString("string(./uuid)", ctxt);
|
uuidstr = virXPathString("string(./uuid)", ctxt);
|
||||||
|
@ -182,7 +179,6 @@ secretXMLParseNode(xmlDocPtr xml, xmlNodePtr root)
|
||||||
"%s", _("malformed uuid element"));
|
"%s", _("malformed uuid element"));
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
VIR_FREE(uuidstr);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
def->description = virXPathString("string(./description)", ctxt);
|
def->description = virXPathString("string(./description)", ctxt);
|
||||||
|
|
Loading…
Reference in New Issue