Skip to content
This repository was archived by the owner on Nov 8, 2023. It is now read-only.

Commit 2af1280

Browse files
namhyungacmel
authored andcommitted
perf annotate-data: Ensure the number of type histograms
Arnaldo reported that there is a case where nr_histograms and histograms don't agree each other. It ended up in a segfault trying to access a NULL histograms array. Let's make sure to update the nr_histograms when the histograms array is changed. Reported-by: Arnaldo Carvalho de Melo <acme@kernel.org> Reviewed-by: Ian Rogers <irogers@google.com> Signed-off-by: Namhyung Kim <namhyung@kernel.org> Tested-by: Arnaldo Carvalho de Melo <acme@redhat.com> Cc: Adrian Hunter <adrian.hunter@intel.com> Cc: Ingo Molnar <mingo@kernel.org> Cc: Jiri Olsa <jolsa@kernel.org> Cc: Kan Liang <kan.liang@linux.intel.com> Cc: Peter Zijlstra <peterz@infradead.org> Link: https://lore.kernel.org/r/20240510210452.2449944-2-namhyung@kernel.org Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
1 parent 9ef3026 commit 2af1280

File tree

1 file changed

+4
-1
lines changed

1 file changed

+4
-1
lines changed

tools/perf/util/annotate-data.c

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1800,7 +1800,6 @@ static int alloc_data_type_histograms(struct annotated_data_type *adt, int nr_en
18001800
sz += sizeof(struct type_hist_entry) * adt->self.size;
18011801

18021802
/* Allocate a table of pointers for each event */
1803-
adt->nr_histograms = nr_entries;
18041803
adt->histograms = calloc(nr_entries, sizeof(*adt->histograms));
18051804
if (adt->histograms == NULL)
18061805
return -ENOMEM;
@@ -1814,6 +1813,8 @@ static int alloc_data_type_histograms(struct annotated_data_type *adt, int nr_en
18141813
if (adt->histograms[i] == NULL)
18151814
goto err;
18161815
}
1816+
1817+
adt->nr_histograms = nr_entries;
18171818
return 0;
18181819

18191820
err:
@@ -1827,7 +1828,9 @@ static void delete_data_type_histograms(struct annotated_data_type *adt)
18271828
{
18281829
for (int i = 0; i < adt->nr_histograms; i++)
18291830
zfree(&(adt->histograms[i]));
1831+
18301832
zfree(&adt->histograms);
1833+
adt->nr_histograms = 0;
18311834
}
18321835

18331836
void annotated_data_type__tree_delete(struct rb_root *root)

0 commit comments

Comments
 (0)