On Sun, Jun 03, 2018 at 01:42:12PM +0530, Sukrit Bhatnagar wrote:
Modify code to use VIR_AUTOFREE macro wherever required.
Signed-off-by: Sukrit Bhatnagar <skrtbhtngr(a)gmail.com>
---
src/util/virfile.c | 303 +++++++++++++++++------------------------------------
1 file changed, 99 insertions(+), 204 deletions(-)
...
@@ -3546,18 +3485,18 @@ virFileGetHugepageSize(const char *path,
static int
virFileGetDefaultHugepageSize(unsigned long long *size)
{
- int ret = -1;
- char *meminfo, *c, *n, *unit;
+ VIR_AUTOFREE(char *) meminfo = NULL;
+ char *c, *n, *unit;
one variable per line...
if (virFileReadAll(PROC_MEMINFO, 4096, &meminfo) < 0)
- goto cleanup;
+ return -1;
if (!(c = strstr(meminfo, HUGEPAGESIZE_STR))) {
virReportError(VIR_ERR_NO_SUPPORT,
_("%s not found in %s"),
HUGEPAGESIZE_STR,
PROC_MEMINFO);
- goto cleanup;
+ return -1;
}
c += strlen(HUGEPAGESIZE_STR);
@@ -3570,13 +3509,10 @@ virFileGetDefaultHugepageSize(unsigned long long *size)
virReportError(VIR_ERR_INTERNAL_ERROR,
_("Unable to parse %s %s"),
HUGEPAGESIZE_STR, c);
- goto cleanup;
+ return -1;
}
- ret = 0;
- cleanup:
- VIR_FREE(meminfo);
- return ret;
+ return 0;
}
# define PROC_MOUNTS "/proc/mounts"
@@ -3589,7 +3525,7 @@ virFileFindHugeTLBFS(virHugeTLBFSPtr *ret_fs,
FILE *f = NULL;
struct mntent mb;
char mntbuf[1024];
- virHugeTLBFSPtr fs = NULL;
+ VIR_AUTOFREE(virHugeTLBFSPtr) fs = NULL;
compound type (internal), needs a dedicated free helper...
size_t nfs = 0;
unsigned long long default_hugepagesz = 0;
@@ -3634,7 +3570,6 @@ virFileFindHugeTLBFS(virHugeTLBFSPtr *ret_fs,
endmntent(f);
while (nfs)
VIR_FREE(fs[--nfs].mnt_dir);
...especially because of ^this...
- VIR_FREE(fs);
return ret;
}
Erik