Skip to content

Commit

Permalink
cpupower: fix potential memory leak
Browse files Browse the repository at this point in the history
Signed-off-by: Thomas Renninger <trenn@suse.com>
Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
  • Loading branch information
Arjun Sreedharan authored and Rafael J. Wysocki committed May 4, 2016
1 parent ac5a181 commit 0b81561
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions tools/power/cpupower/bench/parse.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -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 {
Expand Down

0 comments on commit 0b81561

Please sign in to comment.