mirror of
https://github.com/torvalds/linux.git
synced 2025-12-07 20:06:24 +00:00
perf mem: Don't leak mem event names
When preparing the mem events for the argv copies are intentionally made. These copies are leaked and cause runs of perf using address sanitizer to fail. Rather than leak the memory allocate a chunk of memory for the mem event names upfront and build the strings in this - the storage is sized larger than the previous buffer size. The caller is then responsible for clearing up this memory. As part of this change, remove the mem_loads_name and mem_stores_name global buffers then change the perf_pmu__mem_events_name to write to an out argument buffer. Signed-off-by: Ian Rogers <irogers@google.com> Tested-by: Thomas Falcon <thomas.falcon@intel.com> Reviewed-by: Leo Yan <leo.yan@arm.com> Link: https://lore.kernel.org/r/20250308012853.1384762-1-irogers@google.com Signed-off-by: Namhyung Kim <namhyung@kernel.org>
This commit is contained in:
@@ -3239,6 +3239,7 @@ static int perf_c2c__record(int argc, const char **argv)
|
||||
{
|
||||
int rec_argc, i = 0, j;
|
||||
const char **rec_argv;
|
||||
char *event_name_storage = NULL;
|
||||
int ret;
|
||||
bool all_user = false, all_kernel = false;
|
||||
bool event_set = false;
|
||||
@@ -3300,7 +3301,7 @@ static int perf_c2c__record(int argc, const char **argv)
|
||||
rec_argv[i++] = "--phys-data";
|
||||
rec_argv[i++] = "--sample-cpu";
|
||||
|
||||
ret = perf_mem_events__record_args(rec_argv, &i);
|
||||
ret = perf_mem_events__record_args(rec_argv, &i, &event_name_storage);
|
||||
if (ret)
|
||||
goto out;
|
||||
|
||||
@@ -3327,6 +3328,7 @@ static int perf_c2c__record(int argc, const char **argv)
|
||||
|
||||
ret = cmd_record(i, rec_argv);
|
||||
out:
|
||||
free(event_name_storage);
|
||||
free(rec_argv);
|
||||
return ret;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user