qemu: monitor: Refactor cleanup in qemuMonitorJSONGetAllBlockStatsInfo

Use VIR_AUTOPTR and get rid of the cleanup label.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
This commit is contained in:
Peter Krempa 2019-09-16 16:19:33 +02:00
parent 121911c853
commit f832801a5a

View File

@ -2676,11 +2676,10 @@ qemuMonitorJSONGetAllBlockStatsInfo(qemuMonitorPtr mon,
virHashTablePtr hash, virHashTablePtr hash,
bool backingChain) bool backingChain)
{ {
int ret = -1;
int nstats = 0; int nstats = 0;
int rc; int rc;
size_t i; size_t i;
virJSONValuePtr devices; VIR_AUTOPTR(virJSONValue) devices = NULL;
if (!(devices = qemuMonitorJSONQueryBlockstats(mon))) if (!(devices = qemuMonitorJSONQueryBlockstats(mon)))
return -1; return -1;
@ -2693,14 +2692,14 @@ qemuMonitorJSONGetAllBlockStatsInfo(qemuMonitorPtr mon,
virReportError(VIR_ERR_INTERNAL_ERROR, "%s", virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
_("blockstats device entry was not " _("blockstats device entry was not "
"in expected format")); "in expected format"));
goto cleanup; return -1;
} }
if (!(dev_name = virJSONValueObjectGetString(dev, "device"))) { if (!(dev_name = virJSONValueObjectGetString(dev, "device"))) {
virReportError(VIR_ERR_INTERNAL_ERROR, "%s", virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
_("blockstats device entry was not " _("blockstats device entry was not "
"in expected format")); "in expected format"));
goto cleanup; return -1;
} }
if (*dev_name == '\0') if (*dev_name == '\0')
@ -2710,17 +2709,13 @@ qemuMonitorJSONGetAllBlockStatsInfo(qemuMonitorPtr mon,
backingChain); backingChain);
if (rc < 0) if (rc < 0)
goto cleanup; return -1;
if (rc > nstats) if (rc > nstats)
nstats = rc; nstats = rc;
} }
ret = nstats; return nstats;
cleanup:
virJSONValueFree(devices);
return ret;
} }