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:
Peter Krempa 2021-01-06 15:52:06 +01:00
parent a177c56ddd
commit f07f1c479a

View File

@ -131,7 +131,8 @@ secretXMLParseNode(xmlDocPtr xml, xmlNodePtr root)
{
g_autoptr(xmlXPathContext) ctxt = 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;
if (!virXMLNodeNameEqual(root, "secret")) {
@ -149,24 +150,20 @@ secretXMLParseNode(xmlDocPtr xml, xmlNodePtr root)
def = g_new0(virSecretDef, 1);
prop = virXPathString("string(./@ephemeral)", ctxt);
if (prop != NULL) {
if (virStringParseYesNo(prop, &def->isephemeral) < 0) {
if ((ephemeralstr = virXPathString("string(./@ephemeral)", ctxt))) {
if (virStringParseYesNo(ephemeralstr, &def->isephemeral) < 0) {
virReportError(VIR_ERR_XML_ERROR, "%s",
_("invalid value of 'ephemeral'"));
return NULL;
}
VIR_FREE(prop);
}
prop = virXPathString("string(./@private)", ctxt);
if (prop != NULL) {
if (virStringParseYesNo(prop, &def->isprivate) < 0) {
if ((privatestr = virXPathString("string(./@private)", ctxt))) {
if (virStringParseYesNo(privatestr, &def->isprivate) < 0) {
virReportError(VIR_ERR_XML_ERROR, "%s",
_("invalid value of 'private'"));
return NULL;
}
VIR_FREE(prop);
}
uuidstr = virXPathString("string(./uuid)", ctxt);
@ -182,7 +179,6 @@ secretXMLParseNode(xmlDocPtr xml, xmlNodePtr root)
"%s", _("malformed uuid element"));
return NULL;
}
VIR_FREE(uuidstr);
}
def->description = virXPathString("string(./description)", ctxt);