Automatically free the intermediate JSON data to get rid of the cleanup
section.
Signed-off-by: Peter Krempa <pkrempa(a)redhat.com>
---
src/util/virstoragefile.c | 20 +++++++-------------
1 file changed, 7 insertions(+), 13 deletions(-)
diff --git a/src/util/virstoragefile.c b/src/util/virstoragefile.c
index ba56f452e9..520f531088 100644
--- a/src/util/virstoragefile.c
+++ b/src/util/virstoragefile.c
@@ -3590,22 +3590,21 @@ static int
virStorageSourceParseBackingJSONInternal(virStorageSourcePtr src,
virJSONValuePtr json)
{
- virJSONValuePtr deflattened = NULL;
+ VIR_AUTOPTR(virJSONValue) deflattened = NULL;
virJSONValuePtr file;
const char *drvname;
size_t i;
- int ret = -1;
VIR_AUTOFREE(char *) str = NULL;
if (!(deflattened = virJSONValueObjectDeflatten(json)))
- goto cleanup;
+ return -1;
if (!(file = virJSONValueObjectGetObject(deflattened, "file"))) {
str = virJSONValueToString(json, false);
virReportError(VIR_ERR_INVALID_ARG,
_("JSON backing volume definition '%s' lacks
'file' object"),
NULLSTR(str));
- goto cleanup;
+ return -1;
}
if (!(drvname = virJSONValueObjectGetString(file, "driver"))) {
@@ -3613,23 +3612,18 @@ virStorageSourceParseBackingJSONInternal(virStorageSourcePtr src,
virReportError(VIR_ERR_INVALID_ARG,
_("JSON backing volume definition '%s' lacks driver
name"),
NULLSTR(str));
- goto cleanup;
+ return -1;
}
for (i = 0; i < ARRAY_CARDINALITY(jsonParsers); i++) {
- if (STREQ(drvname, jsonParsers[i].drvname)) {
- ret = jsonParsers[i].func(src, file, jsonParsers[i].opaque);
- goto cleanup;
- }
+ if (STREQ(drvname, jsonParsers[i].drvname))
+ return jsonParsers[i].func(src, file, jsonParsers[i].opaque);
}
virReportError(VIR_ERR_INTERNAL_ERROR,
_("missing parser implementation for JSON backing volume "
"driver '%s'"), drvname);
-
- cleanup:
- virJSONValueFree(deflattened);
- return ret;
+ return -1;
}
--
2.21.0