You need to sign in or sign up before continuing.
提交 ab1021e3 编写于 作者: P Peter Krempa

util: storage: Simplify cleanup path handling in virStorageSourceParseBackingJSONInternal

Automatically free the intermediate JSON data to get rid of the cleanup
section.
Signed-off-by: NPeter Krempa <pkrempa@redhat.com>
Reviewed-by: NJán Tomko <jtomko@redhat.com>
上级 b8222be5
...@@ -3592,22 +3592,21 @@ static int ...@@ -3592,22 +3592,21 @@ static int
virStorageSourceParseBackingJSONInternal(virStorageSourcePtr src, virStorageSourceParseBackingJSONInternal(virStorageSourcePtr src,
virJSONValuePtr json) virJSONValuePtr json)
{ {
virJSONValuePtr deflattened = NULL; VIR_AUTOPTR(virJSONValue) deflattened = NULL;
virJSONValuePtr file; virJSONValuePtr file;
const char *drvname; const char *drvname;
size_t i; size_t i;
int ret = -1;
VIR_AUTOFREE(char *) str = NULL; VIR_AUTOFREE(char *) str = NULL;
if (!(deflattened = virJSONValueObjectDeflatten(json))) if (!(deflattened = virJSONValueObjectDeflatten(json)))
goto cleanup; return -1;
if (!(file = virJSONValueObjectGetObject(deflattened, "file"))) { if (!(file = virJSONValueObjectGetObject(deflattened, "file"))) {
str = virJSONValueToString(json, false); str = virJSONValueToString(json, false);
virReportError(VIR_ERR_INVALID_ARG, virReportError(VIR_ERR_INVALID_ARG,
_("JSON backing volume definition '%s' lacks 'file' object"), _("JSON backing volume definition '%s' lacks 'file' object"),
NULLSTR(str)); NULLSTR(str));
goto cleanup; return -1;
} }
if (!(drvname = virJSONValueObjectGetString(file, "driver"))) { if (!(drvname = virJSONValueObjectGetString(file, "driver"))) {
...@@ -3615,23 +3614,18 @@ virStorageSourceParseBackingJSONInternal(virStorageSourcePtr src, ...@@ -3615,23 +3614,18 @@ virStorageSourceParseBackingJSONInternal(virStorageSourcePtr src,
virReportError(VIR_ERR_INVALID_ARG, virReportError(VIR_ERR_INVALID_ARG,
_("JSON backing volume definition '%s' lacks driver name"), _("JSON backing volume definition '%s' lacks driver name"),
NULLSTR(str)); NULLSTR(str));
goto cleanup; return -1;
} }
for (i = 0; i < ARRAY_CARDINALITY(jsonParsers); i++) { for (i = 0; i < ARRAY_CARDINALITY(jsonParsers); i++) {
if (STREQ(drvname, jsonParsers[i].drvname)) { if (STREQ(drvname, jsonParsers[i].drvname))
ret = jsonParsers[i].func(src, file, jsonParsers[i].opaque); return jsonParsers[i].func(src, file, jsonParsers[i].opaque);
goto cleanup;
}
} }
virReportError(VIR_ERR_INTERNAL_ERROR, virReportError(VIR_ERR_INTERNAL_ERROR,
_("missing parser implementation for JSON backing volume " _("missing parser implementation for JSON backing volume "
"driver '%s'"), drvname); "driver '%s'"), drvname);
return -1;
cleanup:
virJSONValueFree(deflattened);
return ret;
} }
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册