aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorColin Ian King <colin.king@canonical.com>2014-02-18 08:51:30 +0100
committerDaniel Lezcano <daniel.lezcano@free.fr>2014-02-18 08:51:30 +0100
commit761b19925b7509c0212373e6791d6b9b11cb639f (patch)
treeac0a36cd7a08543ae759b5ff51b8d5540672fe8a
parentc302e571cb0c4390095b17a458f2004fd63322a4 (diff)
Fix file and memory resource leak on error exit in idlestat_load
The error returns in idlestat_load fail to close an open file and free allocated memory on the heap. This patch addresses this. Signed-off-by: Colin Ian King <colin.king@canonical.com> Signed-off-by: Daniel Lezcano <daniel.lezcano@linaro.org>
-rw-r--r--idlestat.c14
1 files changed, 11 insertions, 3 deletions
diff --git a/idlestat.c b/idlestat.c
index 739f6dc..0961463 100644
--- a/idlestat.c
+++ b/idlestat.c
@@ -396,16 +396,24 @@ static struct cpuidle_datas *idlestat_load(const char *path)
sscanf(buffer, "cpus=%u", &nrcpus);
}
- if (!nrcpus)
+ if (!nrcpus) {
+ fclose(f);
return ptrerror("read error for 'cpus=' in trace file");
+ }
datas = malloc(sizeof(*datas));
- if (!datas)
+ if (!datas) {
+ fclose(f);
return ptrerror("malloc datas");
+ }
datas->cstates = calloc(sizeof(*datas->cstates), nrcpus);
- if (!datas->cstates)
+ if (!datas->cstates) {
+ free(datas);
+ fclose(f);
return ptrerror("calloc cstate");
+ }
+
/* initialize cstate_max for each cpu */
for (cpu = 0; cpu < nrcpus; cpu++)
datas->cstates[cpu].cstate_max = -1;