diff options
author | Arjun Sreedharan <arjun024@gmail.com> | 2016-04-29 10:00:14 +0300 |
---|---|---|
committer | Rafael J. Wysocki <rafael.j.wysocki@intel.com> | 2016-05-05 02:19:38 +0300 |
commit | 0b81561c1d30bb44e65d3725042e27b548bb1a86 (patch) | |
tree | 32b39db05518a5c25b69b69a5eed07b391f64553 /tools/power/cpupower | |
parent | ac5a181d065d74fb6b213d538f743392f27bcdbd (diff) | |
download | linux-0b81561c1d30bb44e65d3725042e27b548bb1a86.tar.xz |
cpupower: fix potential memory leak
Signed-off-by: Thomas Renninger <trenn@suse.com>
Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
Diffstat (limited to 'tools/power/cpupower')
-rw-r--r-- | tools/power/cpupower/bench/parse.c | 8 |
1 files changed, 5 insertions, 3 deletions
diff --git a/tools/power/cpupower/bench/parse.c b/tools/power/cpupower/bench/parse.c index 2d09c9221ff1..9b65f052081f 100644 --- a/tools/power/cpupower/bench/parse.c +++ b/tools/power/cpupower/bench/parse.c @@ -65,7 +65,7 @@ FILE *prepare_output(const char *dirname) { FILE *output = NULL; int len; - char *filename; + char *filename, *filename_tmp; struct utsname sysdata; DIR *dir; @@ -88,13 +88,15 @@ FILE *prepare_output(const char *dirname) if (uname(&sysdata) == 0) { len += strlen(sysdata.nodename) + strlen(sysdata.release); - filename = realloc(filename, sizeof(char) * len); + filename_tmp = realloc(filename, sizeof(*filename) * len); - if (!filename) { + if (filename_tmp == NULL) { + free(filename); perror("realloc"); goto out_dir; } + filename = filename_tmp; snprintf(filename, len - 1, "%s/benchmark_%s_%s_%li.log", dirname, sysdata.nodename, sysdata.release, time(NULL)); } else { |