Skip to content

Commit bc7a68b

Browse files
abaydurgregkh
authored andcommitted
perf data: Fix double free in perf_session__delete()
commit 69560e3 upstream. When perf_data__create_dir() fails, it calls close_dir(), but perf_session__delete() also calls close_dir() and since dir.version and dir.nr were initialized by perf_data__create_dir(), a double free occurs. This patch moves the initialization of dir.version and dir.nr after successful initialization of dir.files, that prevents double freeing. This behavior is already implemented in perf_data__open_dir(). Fixes: 1455206 ("perf data: Add perf_data__(create_dir|close_dir) functions") Signed-off-by: Alexey Bayduraev <alexey.v.bayduraev@linux.intel.com> Acked-by: Jiri Olsa <jolsa@kernel.org> Cc: Adrian Hunter <adrian.hunter@intel.com> Cc: Alexander Antonov <alexander.antonov@linux.intel.com> Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com> Cc: Alexei Budankov <abudankov@huawei.com> Cc: Andi Kleen <ak@linux.intel.com> Cc: Ingo Molnar <mingo@redhat.com> Cc: Namhyung Kim <namhyung@kernel.org> Cc: Peter Zijlstra <peterz@infradead.org> Link: https://lore.kernel.org/r/20220218152341.5197-2-alexey.v.bayduraev@linux.intel.com Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
1 parent 0565de3 commit bc7a68b

1 file changed

Lines changed: 3 additions & 4 deletions

File tree

‎tools/perf/util/data.c‎

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -44,10 +44,6 @@ int perf_data__create_dir(struct perf_data *data, int nr)
4444
if (!files)
4545
return -ENOMEM;
4646

47-
data->dir.version = PERF_DIR_VERSION;
48-
data->dir.files = files;
49-
data->dir.nr = nr;
50-
5147
for (i = 0; i < nr; i++) {
5248
struct perf_data_file *file = &files[i];
5349

@@ -62,6 +58,9 @@ int perf_data__create_dir(struct perf_data *data, int nr)
6258
file->fd = ret;
6359
}
6460

61+
data->dir.version = PERF_DIR_VERSION;
62+
data->dir.files = files;
63+
data->dir.nr = nr;
6564
return 0;
6665

6766
out_err:

0 commit comments

Comments
 (0)