]> xenbits.xensource.com Git - libvirt.git/commitdiff
util: storage: Simplify cleanup path handling in virStorageSourceParseBackingJSONInternal
authorPeter Krempa <pkrempa@redhat.com>
Thu, 15 Aug 2019 13:41:58 +0000 (15:41 +0200)
committerPeter Krempa <pkrempa@redhat.com>
Mon, 26 Aug 2019 11:49:16 +0000 (13:49 +0200)
Automatically free the intermediate JSON data to get rid of the cleanup
section.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
src/util/virstoragefile.c

index 7288e18b16c47cc1fbce529caec33faad2f16d44..0b68adeb1d31c689f527dacc16af4679b4b98f5b 100644 (file)
@@ -3592,22 +3592,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"))) {
@@ -3615,23 +3614,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;
 }