From: John Ferlan Date: Tue, 7 Mar 2017 11:33:38 +0000 (-0500) Subject: util: Resource some resource leaks in virsysinfo code X-Git-Tag: v3.2.0-rc1~340 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=7744d99415d32f5aab37c567934907960109bea7;p=thirdparty%2Flibvirt.git util: Resource some resource leaks in virsysinfo code 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 --- diff --git a/src/util/virsysinfo.c b/src/util/virsysinfo.c index 7b54bda120..14c17a897d 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: