diff options
author | Peter Schiffer <pschiffe@redhat.com> | 2013-08-29 14:50:10 +0200 |
---|---|---|
committer | Peter Schiffer <pschiffe@redhat.com> | 2013-08-29 14:50:10 +0200 |
commit | 1c9b7c9781b92c4c21e62ecf47cf3413d2d2298a (patch) | |
tree | 415b2d8f300bb635cf6628ce2112aa27cb2aa373 /src/hardware/procfs.c | |
parent | 229d407bf7d03cda4c6b5b9fc5c1102ffc06c2f8 (diff) | |
download | openlmi-providers-1c9b7c9781b92c4c21e62ecf47cf3413d2d2298a.tar.gz openlmi-providers-1c9b7c9781b92c4c21e62ecf47cf3413d2d2298a.tar.xz openlmi-providers-1c9b7c9781b92c4c21e62ecf47cf3413d2d2298a.zip |
Hardware: Fixed Coverity findings
Fixed Coverity findings, enhanced fail case scenarios.
Diffstat (limited to 'src/hardware/procfs.c')
-rw-r--r-- | src/hardware/procfs.c | 32 |
1 files changed, 17 insertions, 15 deletions
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() |