summaryrefslogtreecommitdiff
path: root/tools/power
diff options
context:
space:
mode:
authorColin Ian King <colin.king@canonical.com>2016-04-28 16:24:37 +0300
committerRafael J. Wysocki <rafael.j.wysocki@intel.com>2016-04-28 17:02:28 +0300
commit983d9e065b37dac5aaa2d5a819bdd5b5a0b78c8c (patch)
tree77545e6fe46603334d6c6585ae00532f024e6872 /tools/power
parent04b03594c73c1877a98c7a657cc45bf5e9d89f7c (diff)
downloadlinux-983d9e065b37dac5aaa2d5a819bdd5b5a0b78c8c.tar.xz
cpupower: bench: parse.c: fix several resource leaks
The error handling in prepare_output has several issues with resource leaks. Ensure that filename is free'd and the directory stream DIR is closed before returning. Signed-off-by: Colin Ian King <colin.king@canonical.com> Signed-off-by: Thomas Renninger <trenn@suse.com> Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
Diffstat (limited to 'tools/power')
-rw-r--r--tools/power/cpupower/bench/parse.c14
1 files changed, 11 insertions, 3 deletions
diff --git a/tools/power/cpupower/bench/parse.c b/tools/power/cpupower/bench/parse.c
index f503fb53824e..2d09c9221ff1 100644
--- a/tools/power/cpupower/bench/parse.c
+++ b/tools/power/cpupower/bench/parse.c
@@ -81,14 +81,18 @@ FILE *prepare_output(const char *dirname)
len = strlen(dirname) + 30;
filename = malloc(sizeof(char) * len);
+ if (!filename) {
+ perror("malloc");
+ goto out_dir;
+ }
if (uname(&sysdata) == 0) {
len += strlen(sysdata.nodename) + strlen(sysdata.release);
filename = realloc(filename, sizeof(char) * len);
- if (filename == NULL) {
+ if (!filename) {
perror("realloc");
- return NULL;
+ goto out_dir;
}
snprintf(filename, len - 1, "%s/benchmark_%s_%s_%li.log",
@@ -104,12 +108,16 @@ FILE *prepare_output(const char *dirname)
if (output == NULL) {
perror("fopen");
fprintf(stderr, "error: unable to open logfile\n");
+ goto out;
}
fprintf(stdout, "Logfile: %s\n", filename);
- free(filename);
fprintf(output, "#round load sleep performance powersave percentage\n");
+out:
+ free(filename);
+out_dir:
+ closedir(dir);
return output;
}