Skip to content

Commit 2da77d2

Browse files
John Garrygregkh
authored andcommitted
perf jevents: Fix leak of mapfile memory
[ Upstream commit 3f5777f ] 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>
1 parent 26005b6 commit 2da77d2

1 file changed

Lines changed: 9 additions & 6 deletions

File tree

tools/perf/pmu-events/jevents.c

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1068,10 +1068,9 @@ static int process_one_file(const char *fpath, const struct stat *sb,
10681068
*/
10691069
int main(int argc, char *argv[])
10701070
{
1071-
int rc;
1071+
int rc, ret = 0;
10721072
int maxfds;
10731073
char ldirname[PATH_MAX];
1074-
10751074
const char *arch;
10761075
const char *output_file;
10771076
const char *start_dirname;
@@ -1142,7 +1141,8 @@ int main(int argc, char *argv[])
11421141
/* Make build fail */
11431142
fclose(eventsfp);
11441143
free_arch_std_events();
1145-
return 1;
1144+
ret = 1;
1145+
goto out_free_mapfile;
11461146
} else if (rc) {
11471147
goto empty_map;
11481148
}
@@ -1160,14 +1160,17 @@ int main(int argc, char *argv[])
11601160
/* Make build fail */
11611161
fclose(eventsfp);
11621162
free_arch_std_events();
1163-
return 1;
1163+
ret = 1;
11641164
}
11651165

1166-
return 0;
1166+
1167+
goto out_free_mapfile;
11671168

11681169
empty_map:
11691170
fclose(eventsfp);
11701171
create_empty_mapping(output_file);
11711172
free_arch_std_events();
1172-
return 0;
1173+
out_free_mapfile:
1174+
free(mapfile);
1175+
return ret;
11731176
}

0 commit comments

Comments
 (0)