mirror of
https://gitlab.com/libvirt/libvirt.git
synced 2025-01-25 22:15:20 +00:00
storage_conf: Improve the memory deallocation of virStorageVolDefParseXML
Changes: * Add a new goto label "error" * Free the strings at "cleanup" * Remove the unnecessary frees
This commit is contained in:
parent
6afdfc8e13
commit
107130cc71
@ -1252,7 +1252,7 @@ virStorageVolDefParseXML(virStoragePoolDefPtr pool,
|
|||||||
if (ret->name == NULL) {
|
if (ret->name == NULL) {
|
||||||
virReportError(VIR_ERR_XML_ERROR, "%s",
|
virReportError(VIR_ERR_XML_ERROR, "%s",
|
||||||
_("missing volume name element"));
|
_("missing volume name element"));
|
||||||
goto cleanup;
|
goto error;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Auto-generated so deliberately ignore */
|
/* Auto-generated so deliberately ignore */
|
||||||
@ -1263,20 +1263,17 @@ virStorageVolDefParseXML(virStoragePoolDefPtr pool,
|
|||||||
if (capacity == NULL) {
|
if (capacity == NULL) {
|
||||||
virReportError(VIR_ERR_XML_ERROR, "%s",
|
virReportError(VIR_ERR_XML_ERROR, "%s",
|
||||||
_("missing capacity element"));
|
_("missing capacity element"));
|
||||||
goto cleanup;
|
goto error;
|
||||||
}
|
}
|
||||||
if (virStorageSize(unit, capacity, &ret->capacity) < 0)
|
if (virStorageSize(unit, capacity, &ret->capacity) < 0)
|
||||||
goto cleanup;
|
goto error;
|
||||||
VIR_FREE(capacity);
|
|
||||||
VIR_FREE(unit);
|
VIR_FREE(unit);
|
||||||
|
|
||||||
allocation = virXPathString("string(./allocation)", ctxt);
|
allocation = virXPathString("string(./allocation)", ctxt);
|
||||||
if (allocation) {
|
if (allocation) {
|
||||||
unit = virXPathString("string(./allocation/@unit)", ctxt);
|
unit = virXPathString("string(./allocation/@unit)", ctxt);
|
||||||
if (virStorageSize(unit, allocation, &ret->allocation) < 0)
|
if (virStorageSize(unit, allocation, &ret->allocation) < 0)
|
||||||
goto cleanup;
|
goto error;
|
||||||
VIR_FREE(allocation);
|
|
||||||
VIR_FREE(unit);
|
|
||||||
} else {
|
} else {
|
||||||
ret->allocation = ret->capacity;
|
ret->allocation = ret->capacity;
|
||||||
}
|
}
|
||||||
@ -1293,7 +1290,7 @@ virStorageVolDefParseXML(virStoragePoolDefPtr pool,
|
|||||||
virReportError(VIR_ERR_XML_ERROR,
|
virReportError(VIR_ERR_XML_ERROR,
|
||||||
_("unknown volume format type %s"), format);
|
_("unknown volume format type %s"), format);
|
||||||
VIR_FREE(format);
|
VIR_FREE(format);
|
||||||
goto cleanup;
|
goto error;
|
||||||
}
|
}
|
||||||
VIR_FREE(format);
|
VIR_FREE(format);
|
||||||
}
|
}
|
||||||
@ -1301,14 +1298,14 @@ virStorageVolDefParseXML(virStoragePoolDefPtr pool,
|
|||||||
if (virStorageDefParsePerms(ctxt, &ret->target.perms,
|
if (virStorageDefParsePerms(ctxt, &ret->target.perms,
|
||||||
"./target/permissions",
|
"./target/permissions",
|
||||||
DEFAULT_VOL_PERM_MODE) < 0)
|
DEFAULT_VOL_PERM_MODE) < 0)
|
||||||
goto cleanup;
|
goto error;
|
||||||
|
|
||||||
node = virXPathNode("./target/encryption", ctxt);
|
node = virXPathNode("./target/encryption", ctxt);
|
||||||
if (node != NULL) {
|
if (node != NULL) {
|
||||||
ret->target.encryption = virStorageEncryptionParseNode(ctxt->doc,
|
ret->target.encryption = virStorageEncryptionParseNode(ctxt->doc,
|
||||||
node);
|
node);
|
||||||
if (ret->target.encryption == NULL)
|
if (ret->target.encryption == NULL)
|
||||||
goto cleanup;
|
goto error;
|
||||||
}
|
}
|
||||||
|
|
||||||
ret->backingStore.path = virXPathString("string(./backingStore/path)", ctxt);
|
ret->backingStore.path = virXPathString("string(./backingStore/path)", ctxt);
|
||||||
@ -1323,7 +1320,7 @@ virStorageVolDefParseXML(virStoragePoolDefPtr pool,
|
|||||||
virReportError(VIR_ERR_XML_ERROR,
|
virReportError(VIR_ERR_XML_ERROR,
|
||||||
_("unknown volume format type %s"), format);
|
_("unknown volume format type %s"), format);
|
||||||
VIR_FREE(format);
|
VIR_FREE(format);
|
||||||
goto cleanup;
|
goto error;
|
||||||
}
|
}
|
||||||
VIR_FREE(format);
|
VIR_FREE(format);
|
||||||
}
|
}
|
||||||
@ -1331,16 +1328,18 @@ virStorageVolDefParseXML(virStoragePoolDefPtr pool,
|
|||||||
if (virStorageDefParsePerms(ctxt, &ret->backingStore.perms,
|
if (virStorageDefParsePerms(ctxt, &ret->backingStore.perms,
|
||||||
"./backingStore/permissions",
|
"./backingStore/permissions",
|
||||||
DEFAULT_VOL_PERM_MODE) < 0)
|
DEFAULT_VOL_PERM_MODE) < 0)
|
||||||
goto cleanup;
|
goto error;
|
||||||
|
|
||||||
return ret;
|
|
||||||
|
|
||||||
cleanup:
|
cleanup:
|
||||||
VIR_FREE(allocation);
|
VIR_FREE(allocation);
|
||||||
VIR_FREE(capacity);
|
VIR_FREE(capacity);
|
||||||
VIR_FREE(unit);
|
VIR_FREE(unit);
|
||||||
|
return ret;
|
||||||
|
|
||||||
|
error:
|
||||||
virStorageVolDefFree(ret);
|
virStorageVolDefFree(ret);
|
||||||
return NULL;
|
ret = NULL;
|
||||||
|
goto cleanup;
|
||||||
}
|
}
|
||||||
|
|
||||||
virStorageVolDefPtr
|
virStorageVolDefPtr
|
||||||
|
Loading…
x
Reference in New Issue
Block a user