Skip to content

Commit 3f5777f

Browse files
John Garryacmel
authored andcommitted
perf jevents: Fix leak of mapfile memory
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 <[email protected]> Signed-off-by: John Garry <[email protected]> Cc: Alexander Shishkin <[email protected]> Cc: Andi Kleen <[email protected]> Cc: James Clark <[email protected]> Cc: Joakim Zhang <[email protected]> Cc: Mark Rutland <[email protected]> Cc: Namhyung Kim <[email protected]> Cc: Peter Zijlstra <[email protected]> Cc: Will Deacon <[email protected]> Cc: [email protected] Link: http://lore.kernel.org/lkml/[email protected] Signed-off-by: Arnaldo Carvalho de Melo <[email protected]>
1 parent 7b919a5 commit 3f5777f

File tree

1 file changed

+9
-6
lines changed

1 file changed

+9
-6
lines changed

tools/perf/pmu-events/jevents.c

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1082,10 +1082,9 @@ static int process_one_file(const char *fpath, const struct stat *sb,
10821082
*/
10831083
int main(int argc, char *argv[])
10841084
{
1085-
int rc;
1085+
int rc, ret = 0;
10861086
int maxfds;
10871087
char ldirname[PATH_MAX];
1088-
10891088
const char *arch;
10901089
const char *output_file;
10911090
const char *start_dirname;
@@ -1156,7 +1155,8 @@ int main(int argc, char *argv[])
11561155
/* Make build fail */
11571156
fclose(eventsfp);
11581157
free_arch_std_events();
1159-
return 1;
1158+
ret = 1;
1159+
goto out_free_mapfile;
11601160
} else if (rc) {
11611161
goto empty_map;
11621162
}
@@ -1174,14 +1174,17 @@ int main(int argc, char *argv[])
11741174
/* Make build fail */
11751175
fclose(eventsfp);
11761176
free_arch_std_events();
1177-
return 1;
1177+
ret = 1;
11781178
}
11791179

1180-
return 0;
1180+
1181+
goto out_free_mapfile;
11811182

11821183
empty_map:
11831184
fclose(eventsfp);
11841185
create_empty_mapping(output_file);
11851186
free_arch_std_events();
1186-
return 0;
1187+
out_free_mapfile:
1188+
free(mapfile);
1189+
return ret;
11871190
}

0 commit comments

Comments
 (0)