Calls to virFileReadAll after a VIR_ALLOC that return NULL all show
a memory leak since 'ret' isn't virSysinfoDefFree'd and normal path
"return ret" doesn't free outbuf.
Reported by Coverity
Signed-off-by: John Ferlan <jferlan(a)redhat.com>
---
src/util/virsysinfo.c | 13 +++++++++----
1 file changed, 9 insertions(+), 4 deletions(-)
diff --git a/src/util/virsysinfo.c b/src/util/virsysinfo.c
index 7b54bda..14c17a8 100644
--- a/src/util/virsysinfo.c
+++ b/src/util/virsysinfo.c
@@ -270,7 +270,7 @@ virSysinfoReadPPC(void)
if (virFileReadAll(CPUINFO, CPUINFO_FILE_LEN, &outbuf) < 0) {
virReportError(VIR_ERR_INTERNAL_ERROR,
_("Failed to open %s"), CPUINFO);
- return NULL;
+ goto no_memory;
}
ret->nprocessor = 0;
@@ -281,10 +281,12 @@ virSysinfoReadPPC(void)
if (virSysinfoParsePPCSystem(outbuf, &ret->system) < 0)
goto no_memory;
+ VIR_FREE(outbuf);
return ret;
no_memory:
VIR_FREE(outbuf);
+ virSysinfoDefFree(ret);
return NULL;
}
@@ -402,7 +404,7 @@ virSysinfoReadARM(void)
if (virFileReadAll(CPUINFO, CPUINFO_FILE_LEN, &outbuf) < 0) {
virReportError(VIR_ERR_INTERNAL_ERROR,
_("Failed to open %s"), CPUINFO);
- return NULL;
+ goto no_memory;
}
ret->nprocessor = 0;
@@ -413,10 +415,12 @@ virSysinfoReadARM(void)
if (virSysinfoParseARMSystem(outbuf, &ret->system) < 0)
goto no_memory;
+ VIR_FREE(outbuf);
return ret;
no_memory:
VIR_FREE(outbuf);
+ virSysinfoDefFree(ret);
return NULL;
}
@@ -539,7 +543,7 @@ virSysinfoReadS390(void)
if (virFileReadAll(CPUINFO, CPUINFO_FILE_LEN, &outbuf) < 0) {
virReportError(VIR_ERR_INTERNAL_ERROR,
_("Failed to open %s"), CPUINFO);
- return NULL;
+ goto no_memory;
}
ret->nprocessor = 0;
@@ -554,12 +558,13 @@ virSysinfoReadS390(void)
if (virFileReadAll(SYSINFO, 8192, &outbuf) < 0) {
virReportError(VIR_ERR_INTERNAL_ERROR,
_("Failed to open %s"), SYSINFO);
- return NULL;
+ goto no_memory;
}
if (virSysinfoParseS390System(outbuf, &ret->system) < 0)
goto no_memory;
+ VIR_FREE(outbuf);
return ret;
no_memory:
--
2.9.3