Skip to content

Commit

Permalink
perf jevents: Fix leak of mapfile memory
Browse files Browse the repository at this point in the history
The memory for global pointer is never freed during normal program
execution, so let's do that in the main function exit as a good
programming practice.

A stray blank line is also removed.

Reported-by: Jiri Olsa <jolsa@redhat.com>
Signed-off-by: John Garry <john.garry@huawei.com>
Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com>
Cc: Andi Kleen <ak@linux.intel.com>
Cc: James Clark <james.clark@arm.com>
Cc: Joakim Zhang <qiangqing.zhang@nxp.com>
Cc: Mark Rutland <mark.rutland@arm.com>
Cc: Namhyung Kim <namhyung@kernel.org>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Will Deacon <will@kernel.org>
Cc: linuxarm@huawei.com
Link: http://lore.kernel.org/lkml/1583406486-154841-2-git-send-email-john.garry@huawei.com
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
  • Loading branch information
John Garry authored and Arnaldo Carvalho de Melo committed Mar 6, 2020
1 parent 7b919a5 commit 3f5777f
Showing 1 changed file with 9 additions and 6 deletions.
15 changes: 9 additions & 6 deletions tools/perf/pmu-events/jevents.c
Original file line number Diff line number Diff line change
Expand Up @@ -1082,10 +1082,9 @@ static int process_one_file(const char *fpath, const struct stat *sb,
*/
int main(int argc, char *argv[])
{
int rc;
int rc, ret = 0;
int maxfds;
char ldirname[PATH_MAX];

const char *arch;
const char *output_file;
const char *start_dirname;
Expand Down Expand Up @@ -1156,7 +1155,8 @@ int main(int argc, char *argv[])
/* Make build fail */
fclose(eventsfp);
free_arch_std_events();
return 1;
ret = 1;
goto out_free_mapfile;
} else if (rc) {
goto empty_map;
}
Expand All @@ -1174,14 +1174,17 @@ int main(int argc, char *argv[])
/* Make build fail */
fclose(eventsfp);
free_arch_std_events();
return 1;
ret = 1;
}

return 0;

goto out_free_mapfile;

empty_map:
fclose(eventsfp);
create_empty_mapping(output_file);
free_arch_std_events();
return 0;
out_free_mapfile:
free(mapfile);
return ret;
}

0 comments on commit 3f5777f

Please sign in to comment.