提交 4fe2eea3 编写于 作者: S Sukrit Bhatnagar 提交者: Erik Skultety

util: qemu: use VIR_AUTOFREE instead of VIR_FREE for scalar types

By making use of GNU C's cleanup attribute handled by the
VIR_AUTOFREE macro for declaring scalar variables, majority
of the VIR_FREE calls can be dropped, which in turn leads to
getting rid of most of our cleanup sections.
Signed-off-by: NSukrit Bhatnagar <skrtbhtngr@gmail.com>
Reviewed-by: NErik Skultety <eskultet@redhat.com>
上级 c3a2e274
......@@ -85,29 +85,22 @@ virQEMUBuildCommandLineJSONArrayNumbered(const char *key,
virBufferPtr buf)
{
virJSONValuePtr member;
char *prefix = NULL;
size_t i;
int ret = 0;
for (i = 0; i < virJSONValueArraySize(array); i++) {
member = virJSONValueArrayGet((virJSONValuePtr) array, i);
VIR_AUTOFREE(char *) prefix = NULL;
if (virAsprintf(&prefix, "%s.%zu", key, i) < 0)
goto cleanup;
return 0;
if (virQEMUBuildCommandLineJSONRecurse(prefix, member, buf,
virQEMUBuildCommandLineJSONArrayNumbered,
true) < 0)
goto cleanup;
VIR_FREE(prefix);
return 0;
}
ret = 0;
cleanup:
VIR_FREE(prefix);
return ret;
return 0;
}
......@@ -118,23 +111,19 @@ virQEMUBuildCommandLineJSONIterate(const char *key,
void *opaque)
{
struct virQEMUCommandLineJSONIteratorData *data = opaque;
char *tmpkey = NULL;
int ret = -1;
if (data->prefix) {
VIR_AUTOFREE(char *) tmpkey = NULL;
if (virAsprintf(&tmpkey, "%s.%s", data->prefix, key) < 0)
return -1;
ret = virQEMUBuildCommandLineJSONRecurse(tmpkey, value, data->buf,
return virQEMUBuildCommandLineJSONRecurse(tmpkey, value, data->buf,
data->arrayFunc, false);
VIR_FREE(tmpkey);
} else {
ret = virQEMUBuildCommandLineJSONRecurse(key, value, data->buf,
return virQEMUBuildCommandLineJSONRecurse(key, value, data->buf,
data->arrayFunc, false);
}
return ret;
}
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册