Commit 0b81561c authored by Arjun Sreedharan's avatar Arjun Sreedharan Committed by Rafael J. Wysocki

cpupower: fix potential memory leak

Signed-off-by: default avatarThomas Renninger <trenn@suse.com>
Signed-off-by: default avatarRafael J. Wysocki <rafael.j.wysocki@intel.com>
parent ac5a181d
...@@ -65,7 +65,7 @@ FILE *prepare_output(const char *dirname) ...@@ -65,7 +65,7 @@ FILE *prepare_output(const char *dirname)
{ {
FILE *output = NULL; FILE *output = NULL;
int len; int len;
char *filename; char *filename, *filename_tmp;
struct utsname sysdata; struct utsname sysdata;
DIR *dir; DIR *dir;
...@@ -88,13 +88,15 @@ FILE *prepare_output(const char *dirname) ...@@ -88,13 +88,15 @@ FILE *prepare_output(const char *dirname)
if (uname(&sysdata) == 0) { if (uname(&sysdata) == 0) {
len += strlen(sysdata.nodename) + strlen(sysdata.release); 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"); perror("realloc");
goto out_dir; goto out_dir;
} }
filename = filename_tmp;
snprintf(filename, len - 1, "%s/benchmark_%s_%s_%li.log", snprintf(filename, len - 1, "%s/benchmark_%s_%s_%li.log",
dirname, sysdata.nodename, sysdata.release, time(NULL)); dirname, sysdata.nodename, sysdata.release, time(NULL));
} else { } else {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment