[PATCH] lib: fwts_cpu: free cpu on error

Colin King colin.king at canonical.com
Mon May 6 22:02:29 UTC 2013


From: Colin Ian King <colin.king at canonical.com>

Coverity CID #997346, Resource leak.

Need to free cpu before we return.

Signed-off-by: Colin Ian King <colin.king at canonical.com>
---
 src/lib/src/fwts_cpu.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/src/lib/src/fwts_cpu.c b/src/lib/src/fwts_cpu.c
index d6c11ba..282bc42 100644
--- a/src/lib/src/fwts_cpu.c
+++ b/src/lib/src/fwts_cpu.c
@@ -114,8 +114,10 @@ fwts_cpuinfo_x86 *fwts_cpu_get_info(const int which_cpu)
 	if ((cpu = (fwts_cpuinfo_x86*)calloc(1, sizeof(fwts_cpuinfo_x86))) == NULL)
 		return NULL;
 
-	if ((fp = fopen("/proc/cpuinfo", "r")) == NULL)
+	if ((fp = fopen("/proc/cpuinfo", "r")) == NULL) {
+		free(cpu);
 		return NULL;
+	}
 
 	while (fgets(buffer, sizeof(buffer), fp) != NULL) {
 		char *ptr = strstr(buffer, ":");
-- 
1.8.1.2




More information about the fwts-devel mailing list