aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLisa Nguyen <lisa.nguyen@linaro.org>2016-11-07 12:44:10 -0800
committerLisa Nguyen <lisa.nguyen@linaro.org>2016-11-07 12:44:10 -0800
commit45b478c763bfaefbda5518d4e6900193d1e65ad0 (patch)
tree134debb68a0a41f16b4d51a4151b05b3da5801e9
parent1070827f12ca6613fde6f2abb8f8334cf4c3879c (diff)
downloadidlestat-45b478c763bfaefbda5518d4e6900193d1e65ad0.tar.gz
Fix resource leak in output_cstate_info() and build_cstate_info()
Coverity Scan detected a resource leak in build_cstate_info() and output_cstate_info() functions. Refer to defect #84131. Valgrind confirms the memory leak as well: ==41915== 4,768 bytes in 1 blocks are definitely lost in loss record 6 of 8 ==41915== at 0x4C2F948: calloc (vg_replace_malloc.c:711) ==41915== by 0x40232B: build_cstate_info (idlestat.c:318) ==41915== by 0x403DD1: output_cstate_info (idlestat.c:937) ==41915== by 0x404D53: idlestat_store (idlestat.c:1286) ==41915== by 0x4055A8: main (idlestat.c:1532) Fix this issue by rewritting the syntax for the calloc function inside build_cstate_info(), so the pointer can be easily deferenced later. Also, deallocate any memory that was created locally inside output_cstate_info(). Signed-off-by: Lisa Nguyen <lisa.nguyen@linaro.org>
-rw-r--r--idlestat.c4
1 files changed, 3 insertions, 1 deletions
diff --git a/idlestat.c b/idlestat.c
index 5571ae8..93ac86a 100644
--- a/idlestat.c
+++ b/idlestat.c
@@ -315,7 +315,7 @@ struct cpuidle_cstates *build_cstate_info(int nrcpus)
assert(nrcpus > 0);
- cstates = calloc(nrcpus, sizeof(*cstates));
+ cstates = (struct cpuidle_cstates *)calloc(nrcpus, sizeof(struct cpuidle_cstates));
if (!cstates)
return ptrerror(__func__);
@@ -947,6 +947,8 @@ void output_cstate_info(FILE *f, struct cpu_topology * topo, int nrcpus)
cstates[i].cstate[j].target_residency);
}
}
+
+ free(cstates);
}
#define TRACE_IRQ_FORMAT "%*[^[][%d] %*[^=]=%d%*[^=]=%16s"