Use automatic memory allocation and move variables into correct scope to simplify the code and remove the need for a 'cleanup:' label. Signed-off-by: Peter Krempa <pkrempa@xxxxxxxxxx> --- src/qemu/qemu_migration_params.c | 40 ++++++++++++-------------------- 1 file changed, 15 insertions(+), 25 deletions(-) diff --git a/src/qemu/qemu_migration_params.c b/src/qemu/qemu_migration_params.c index 9b6601367a..38a5a91f2a 100644 --- a/src/qemu/qemu_migration_params.c +++ b/src/qemu/qemu_migration_params.c @@ -1265,44 +1265,42 @@ int qemuMigrationParamsParse(xmlXPathContextPtr ctxt, qemuMigrationParamsPtr *migParams) { - qemuMigrationParamsPtr params = NULL; + g_autoptr(qemuMigrationParams) params = NULL; qemuMigrationParamValuePtr pv; - xmlNodePtr *nodes = NULL; - char *name = NULL; - char *value = NULL; - int param; + g_autofree xmlNodePtr *nodes = NULL; size_t i; int rc; int n; - int ret = -1; *migParams = NULL; if ((rc = virXPathBoolean("boolean(./migParams)", ctxt)) < 0) - goto cleanup; + return -1; - if (rc == 0) { - ret = 0; - goto cleanup; - } + if (rc == 0) + return 0; if ((n = virXPathNodeSet("./migParams[1]/param", ctxt, &nodes)) < 0) return -1; if (!(params = qemuMigrationParamsNew())) - goto cleanup; + return -1; for (i = 0; i < n; i++) { + g_autofree char *name = NULL; + g_autofree char *value = NULL; + int param; + if (!(name = virXMLPropString(nodes[i], "name"))) { virReportError(VIR_ERR_INTERNAL_ERROR, "%s", _("missing migration parameter name")); - goto cleanup; + return -1; } if ((param = qemuMigrationParamTypeFromString(name)) < 0) { virReportError(VIR_ERR_INTERNAL_ERROR, _("unknown migration parameter '%s'"), name); - goto cleanup; + return -1; } pv = ¶ms->params[param]; @@ -1310,7 +1308,7 @@ qemuMigrationParamsParse(xmlXPathContextPtr ctxt, virReportError(VIR_ERR_INTERNAL_ERROR, _("missing value for migration parameter '%s'"), name); - goto cleanup; + return -1; } rc = 0; @@ -1336,23 +1334,15 @@ qemuMigrationParamsParse(xmlXPathContextPtr ctxt, virReportError(VIR_ERR_INTERNAL_ERROR, _("invalid value '%s' for migration parameter '%s'"), value, name); - goto cleanup; + return -1; } pv->set = true; - VIR_FREE(name); - VIR_FREE(value); } *migParams = g_steal_pointer(¶ms); - ret = 0; - cleanup: - qemuMigrationParamsFree(params); - VIR_FREE(nodes); - VIR_FREE(name); - VIR_FREE(value); - return ret; + return 0; } -- 2.26.2