From 1c9b7c9781b92c4c21e62ecf47cf3413d2d2298a Mon Sep 17 00:00:00 2001 From: Peter Schiffer Date: Thu, 29 Aug 2013 14:50:10 +0200 Subject: Hardware: Fixed Coverity findings Fixed Coverity findings, enhanced fail case scenarios. --- src/hardware/procfs.c | 32 +++++++++++++++++--------------- 1 file changed, 17 insertions(+), 15 deletions(-) (limited to 'src/hardware/procfs.c') diff --git a/src/hardware/procfs.c b/src/hardware/procfs.c index 288c8a9..3c01cd4 100644 --- a/src/hardware/procfs.c +++ b/src/hardware/procfs.c @@ -63,7 +63,7 @@ short cpuinfo_get_processor(CpuinfoProcessor *cpu) { short ret = -1; unsigned i, buffer_size = 0; - char **buffer = NULL, *buf; + char **buffer = NULL, *buf = NULL; /* read /proc/cpuinfo file */ if (read_file("/proc/cpuinfo", &buffer, &buffer_size) != 0) { @@ -112,6 +112,7 @@ short cpuinfo_get_processor(CpuinfoProcessor *cpu) done: free_2d_buffer(&buffer, &buffer_size); + free(buf); if (ret != 0) { cpuinfo_free_processor(cpu); @@ -122,23 +123,24 @@ done: void cpuinfo_free_processor(CpuinfoProcessor *cpu) { - if (cpu) { - if (cpu->flags_nb > 0) { - unsigned i; - for (i = 0; i < cpu->flags_nb; i++) { - free(cpu->flags[i]); - cpu->flags[i] = NULL; - } - free(cpu->flags); - } - cpu->flags_nb = 0; - cpu->flags = NULL; + unsigned i; - free(cpu->model_name); - cpu->model_name = NULL; + if (!cpu) { + return; } - return; + if (cpu->flags && cpu->flags_nb > 0) { + for (i = 0; i < cpu->flags_nb; i++) { + free(cpu->flags[i]); + cpu->flags[i] = NULL; + } + free(cpu->flags); + } + cpu->flags_nb = 0; + cpu->flags = NULL; + + free(cpu->model_name); + cpu->model_name = NULL; } unsigned long meminfo_get_memory_size() -- cgit