Skip to content
Snippets Groups Projects
Commit 51e96061 authored by Alexey Bayduraev's avatar Alexey Bayduraev Committed by Greg Kroah-Hartman
Browse files

perf data: Fix double free in perf_session__delete()


commit 69560e36 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: 14552063 ("perf data: Add perf_data__(create_dir|close_dir) functions")
Signed-off-by: default avatarAlexey Bayduraev <alexey.v.bayduraev@linux.intel.com>
Acked-by: default avatarJiri 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: default avatarArnaldo Carvalho de Melo <acme@redhat.com>
Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
parent 5419b5be
No related branches found
No related tags found
2 merge requests!33Integrate changes of 5.10.116 version from ST,!21v5.10-ktn: Bump patch release from 5.10.95 to 5.10.103
...@@ -44,10 +44,6 @@ int perf_data__create_dir(struct perf_data *data, int nr) ...@@ -44,10 +44,6 @@ int perf_data__create_dir(struct perf_data *data, int nr)
if (!files) if (!files)
return -ENOMEM; return -ENOMEM;
data->dir.version = PERF_DIR_VERSION;
data->dir.files = files;
data->dir.nr = nr;
for (i = 0; i < nr; i++) { for (i = 0; i < nr; i++) {
struct perf_data_file *file = &files[i]; struct perf_data_file *file = &files[i];
...@@ -62,6 +58,9 @@ int perf_data__create_dir(struct perf_data *data, int nr) ...@@ -62,6 +58,9 @@ int perf_data__create_dir(struct perf_data *data, int nr)
file->fd = ret; file->fd = ret;
} }
data->dir.version = PERF_DIR_VERSION;
data->dir.files = files;
data->dir.nr = nr;
return 0; return 0;
out_err: out_err:
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment