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: Sukrit Bhatnagar <skrtbhtngr@gmail.com>
Reviewed-by: Erik Skultety <eskultet@redhat.com>
This commit is contained in:
Sukrit Bhatnagar 2018-07-13 23:24:45 +05:30 committed by Erik Skultety
parent 46a1f0bb64
commit d9caa2bc93

View File

@ -822,12 +822,9 @@ virExec(virCommandPtr cmd)
int
virRun(const char *const*argv, int *status)
{
int ret;
virCommandPtr cmd = virCommandNewArgs(argv);
VIR_AUTOPTR(virCommand) cmd = virCommandNewArgs(argv);
ret = virCommandRun(cmd, status);
virCommandFree(cmd);
return ret;
return virCommandRun(cmd, status);
}
#else /* WIN32 */
@ -2960,7 +2957,7 @@ virCommandRunRegex(virCommandPtr cmd,
int totgroups = 0, ngroup = 0, maxvars = 0;
char **groups;
VIR_AUTOFREE(char *) outbuf = NULL;
char **lines = NULL;
VIR_AUTOPTR(virString) lines = NULL;
int ret = -1;
/* Compile all regular expressions */
@ -3039,7 +3036,6 @@ virCommandRunRegex(virCommandPtr cmd,
ret = 0;
cleanup:
virStringListFree(lines);
if (groups) {
for (j = 0; j < totgroups; j++)
VIR_FREE(groups[j]);