mirror of
https://gitlab.com/libvirt/libvirt.git
synced 2025-03-07 17:28:15 +00:00
qemuMigrationCookieCapsXMLParse: Refactor memory handling
Use modern allocators, automatic memory feeing, and decrease the scope of some variables to remove the 'cleanup' label. Signed-off-by: Peter Krempa <pkrempa@redhat.com> Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
This commit is contained in:
parent
9d7ca30ece
commit
83434e5acd
@ -1054,29 +1054,26 @@ qemuMigrationCookieStatisticsXMLParse(xmlXPathContextPtr ctxt)
|
|||||||
static qemuMigrationCookieCapsPtr
|
static qemuMigrationCookieCapsPtr
|
||||||
qemuMigrationCookieCapsXMLParse(xmlXPathContextPtr ctxt)
|
qemuMigrationCookieCapsXMLParse(xmlXPathContextPtr ctxt)
|
||||||
{
|
{
|
||||||
qemuMigrationCookieCapsPtr caps = NULL;
|
g_autoptr(qemuMigrationCookieCaps) caps = g_new0(qemuMigrationCookieCaps, 1);
|
||||||
xmlNodePtr *nodes = NULL;
|
g_autofree xmlNodePtr *nodes = NULL;
|
||||||
qemuMigrationCookieCapsPtr ret = NULL;
|
|
||||||
char *name = NULL;
|
|
||||||
char *automatic = NULL;
|
|
||||||
int cap;
|
|
||||||
size_t i;
|
size_t i;
|
||||||
int n;
|
int n;
|
||||||
|
|
||||||
if (VIR_ALLOC(caps) < 0)
|
|
||||||
return NULL;
|
|
||||||
|
|
||||||
caps->supported = virBitmapNew(QEMU_MIGRATION_CAP_LAST);
|
caps->supported = virBitmapNew(QEMU_MIGRATION_CAP_LAST);
|
||||||
caps->automatic = virBitmapNew(QEMU_MIGRATION_CAP_LAST);
|
caps->automatic = virBitmapNew(QEMU_MIGRATION_CAP_LAST);
|
||||||
|
|
||||||
if ((n = virXPathNodeSet("./capabilities[1]/cap", ctxt, &nodes)) < 0)
|
if ((n = virXPathNodeSet("./capabilities[1]/cap", ctxt, &nodes)) < 0)
|
||||||
goto cleanup;
|
return NULL;
|
||||||
|
|
||||||
for (i = 0; i < n; i++) {
|
for (i = 0; i < n; i++) {
|
||||||
|
g_autofree char *name = NULL;
|
||||||
|
g_autofree char *automatic = NULL;
|
||||||
|
int cap;
|
||||||
|
|
||||||
if (!(name = virXMLPropString(nodes[i], "name"))) {
|
if (!(name = virXMLPropString(nodes[i], "name"))) {
|
||||||
virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
|
virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
|
||||||
_("missing migration capability name"));
|
_("missing migration capability name"));
|
||||||
goto cleanup;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ((cap = qemuMigrationCapabilityTypeFromString(name)) < 0)
|
if ((cap = qemuMigrationCapabilityTypeFromString(name)) < 0)
|
||||||
@ -1087,19 +1084,9 @@ qemuMigrationCookieCapsXMLParse(xmlXPathContextPtr ctxt)
|
|||||||
if ((automatic = virXMLPropString(nodes[i], "auto")) &&
|
if ((automatic = virXMLPropString(nodes[i], "auto")) &&
|
||||||
STREQ(automatic, "yes"))
|
STREQ(automatic, "yes"))
|
||||||
ignore_value(virBitmapSetBit(caps->automatic, cap));
|
ignore_value(virBitmapSetBit(caps->automatic, cap));
|
||||||
|
|
||||||
VIR_FREE(name);
|
|
||||||
VIR_FREE(automatic);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
ret = g_steal_pointer(&caps);
|
return g_steal_pointer(&caps);
|
||||||
|
|
||||||
cleanup:
|
|
||||||
qemuMigrationCookieCapsFree(caps);
|
|
||||||
VIR_FREE(nodes);
|
|
||||||
VIR_FREE(name);
|
|
||||||
VIR_FREE(automatic);
|
|
||||||
return ret;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user