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

util: command: use VIR_AUTOPTR for aggregate types

By making use of GNU C's cleanup attribute handled by the
VIR_AUTOPTR macro for declaring aggregate pointer variables,
majority of the calls to *Free functions 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>
上级 46a1f0bb
...@@ -822,12 +822,9 @@ virExec(virCommandPtr cmd) ...@@ -822,12 +822,9 @@ virExec(virCommandPtr cmd)
int int
virRun(const char *const*argv, int *status) virRun(const char *const*argv, int *status)
{ {
int ret; VIR_AUTOPTR(virCommand) cmd = virCommandNewArgs(argv);
virCommandPtr cmd = virCommandNewArgs(argv);
ret = virCommandRun(cmd, status); return virCommandRun(cmd, status);
virCommandFree(cmd);
return ret;
} }
#else /* WIN32 */ #else /* WIN32 */
...@@ -2960,7 +2957,7 @@ virCommandRunRegex(virCommandPtr cmd, ...@@ -2960,7 +2957,7 @@ virCommandRunRegex(virCommandPtr cmd,
int totgroups = 0, ngroup = 0, maxvars = 0; int totgroups = 0, ngroup = 0, maxvars = 0;
char **groups; char **groups;
VIR_AUTOFREE(char *) outbuf = NULL; VIR_AUTOFREE(char *) outbuf = NULL;
char **lines = NULL; VIR_AUTOPTR(virString) lines = NULL;
int ret = -1; int ret = -1;
/* Compile all regular expressions */ /* Compile all regular expressions */
...@@ -3039,7 +3036,6 @@ virCommandRunRegex(virCommandPtr cmd, ...@@ -3039,7 +3036,6 @@ virCommandRunRegex(virCommandPtr cmd,
ret = 0; ret = 0;
cleanup: cleanup:
virStringListFree(lines);
if (groups) { if (groups) {
for (j = 0; j < totgroups; j++) for (j = 0; j < totgroups; j++)
VIR_FREE(groups[j]); VIR_FREE(groups[j]);
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册