提交 7744d994 编写于 作者: J John Ferlan

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: NJohn Ferlan <jferlan@redhat.com>
上级 ee42957b
......@@ -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:
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册