Skip to content

Commit b0fb978

Browse files
WangNan0acmel
authored andcommitted
perf tools: Fix mmap2 event allocation in synthesize code
perf_event__synthesize_mmap_events() issues mmap2 events, but the memory of that event is allocated using: mmap_event = malloc(sizeof(mmap_event->mmap) + machine->id_hdr_size); If path of mmap source file is long (near PATH_MAX), random crash would happen. Should use sizeof(mmap_event->mmap2). Fix two memory allocations. Signed-off-by: Wang Nan <wangnan0@huawei.com> Reviewed-by: Masami Hiramatsu <masami.hiramatsu.pt@hitachi.com> Acked-by: Jiri Olsa <jolsa@kernel.org> Cc: He Kuang <hekuang@huawei.com> Cc: Namhyung Kim <namhyung@kernel.org> Cc: Zefan Li <lizefan@huawei.com> Cc: pi3orama@163.com Link: http://lkml.kernel.org/r/1452593524-138970-1-git-send-email-wangnan0@huawei.com Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
1 parent 8a59f3c commit b0fb978

1 file changed

Lines changed: 2 additions & 2 deletions

File tree

‎tools/perf/util/event.c‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -503,7 +503,7 @@ int perf_event__synthesize_thread_map(struct perf_tool *tool,
503503
if (comm_event == NULL)
504504
goto out;
505505

506-
mmap_event = malloc(sizeof(mmap_event->mmap) + machine->id_hdr_size);
506+
mmap_event = malloc(sizeof(mmap_event->mmap2) + machine->id_hdr_size);
507507
if (mmap_event == NULL)
508508
goto out_free_comm;
509509

@@ -577,7 +577,7 @@ int perf_event__synthesize_threads(struct perf_tool *tool,
577577
if (comm_event == NULL)
578578
goto out;
579579

580-
mmap_event = malloc(sizeof(mmap_event->mmap) + machine->id_hdr_size);
580+
mmap_event = malloc(sizeof(mmap_event->mmap2) + machine->id_hdr_size);
581581
if (mmap_event == NULL)
582582
goto out_free_comm;
583583

0 commit comments

Comments
 (0)