util: netdevveth: 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: Sukrit Bhatnagar <skrtbhtngr@gmail.com>
Reviewed-by: Erik Skultety <eskultet@redhat.com>
This commit is contained in:
Sukrit Bhatnagar 2018-07-28 23:31:35 +05:30 committed by Erik Skultety
parent f84b0f1499
commit 8758a44957

View File

@ -46,12 +46,12 @@ virMutex virNetDevVethCreateMutex = VIR_MUTEX_INITIALIZER;
static int virNetDevVethExists(int devNum)
{
int ret;
char *path = NULL;
VIR_AUTOFREE(char *) path = NULL;
if (virAsprintf(&path, SYSFS_NET_DIR "vnet%d/", devNum) < 0)
return -1;
ret = virFileExists(path) ? 1 : 0;
VIR_DEBUG("Checked dev vnet%d usage: %d", devNum, ret);
VIR_FREE(path);
return ret;
}
@ -111,8 +111,6 @@ static int virNetDevVethGetFreeNum(int startDev)
int virNetDevVethCreate(char** veth1, char** veth2)
{
int ret = -1;
char *veth1auto = NULL;
char *veth2auto = NULL;
int vethNum = 0;
virCommandPtr cmd = NULL;
size_t i;
@ -125,6 +123,9 @@ int virNetDevVethCreate(char** veth1, char** veth2)
#define MAX_VETH_RETRIES 10
for (i = 0; i < MAX_VETH_RETRIES; i++) {
VIR_AUTOFREE(char *) veth1auto = NULL;
VIR_AUTOFREE(char *) veth2auto = NULL;
int status;
if (!*veth1) {
int veth1num;
@ -173,8 +174,6 @@ int virNetDevVethCreate(char** veth1, char** veth2)
*veth1 ? *veth1 : veth1auto,
*veth2 ? *veth2 : veth2auto,
status);
VIR_FREE(veth1auto);
VIR_FREE(veth2auto);
virCommandFree(cmd);
cmd = NULL;
}
@ -186,8 +185,6 @@ int virNetDevVethCreate(char** veth1, char** veth2)
cleanup:
virMutexUnlock(&virNetDevVethCreateMutex);
virCommandFree(cmd);
VIR_FREE(veth1auto);
VIR_FREE(veth2auto);
return ret;
}