perf jevents: Fix leak of mapfile memory

[ Upstream commit 3f5777fbaf04c58d940526a22a2e0c813c837936 ]

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>
Signed-off-by: Sasha Levin <sashal@kernel.org>
This commit is contained in:
John Garry 2020-03-05 19:08:01 +08:00 committed by Greg Kroah-Hartman
parent 47c5fa5b55
commit 2002c630a9

View file

@ -1064,10 +1064,9 @@ static int process_one_file(const char *fpath, const struct stat *sb,
*/ */
int main(int argc, char *argv[]) int main(int argc, char *argv[])
{ {
int rc; int rc, ret = 0;
int maxfds; int maxfds;
char ldirname[PATH_MAX]; char ldirname[PATH_MAX];
const char *arch; const char *arch;
const char *output_file; const char *output_file;
const char *start_dirname; const char *start_dirname;
@ -1138,7 +1137,8 @@ int main(int argc, char *argv[])
/* Make build fail */ /* Make build fail */
fclose(eventsfp); fclose(eventsfp);
free_arch_std_events(); free_arch_std_events();
return 1; ret = 1;
goto out_free_mapfile;
} else if (rc) { } else if (rc) {
goto empty_map; goto empty_map;
} }
@ -1156,14 +1156,17 @@ int main(int argc, char *argv[])
/* Make build fail */ /* Make build fail */
fclose(eventsfp); fclose(eventsfp);
free_arch_std_events(); free_arch_std_events();
return 1; ret = 1;
} }
return 0;
goto out_free_mapfile;
empty_map: empty_map:
fclose(eventsfp); fclose(eventsfp);
create_empty_mapping(output_file); create_empty_mapping(output_file);
free_arch_std_events(); free_arch_std_events();
return 0; out_free_mapfile:
free(mapfile);
return ret;
} }