Skip to content

Commit a4c17eb

Browse files
captain5050gregkh
authored andcommitted
perf hist: Fix memory leak of a perf_hpp_fmt
[ Upstream commit 0ca1f53 ] perf_hpp__column_unregister() removes an entry from a list but doesn't free the memory causing a memory leak spotted by leak sanitizer. Add the free while at the same time reducing the scope of the function to static. Signed-off-by: Ian Rogers <irogers@google.com> Reviewed-by: Kajol Jain <kjain@linux.ibm.com> Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com> Cc: Jiri Olsa <jolsa@redhat.com> Cc: Mark Rutland <mark.rutland@arm.com> Cc: Namhyung Kim <namhyung@kernel.org> Cc: Peter Zijlstra <peterz@infradead.org> Cc: Stephane Eranian <eranian@google.com> Link: http://lore.kernel.org/lkml/20211118071247.2140392-1-irogers@google.com Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com> Signed-off-by: Sasha Levin <sashal@kernel.org>
1 parent d9b7227 commit a4c17eb

2 files changed

Lines changed: 14 additions & 15 deletions

File tree

‎tools/perf/ui/hist.c‎

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -535,6 +535,18 @@ struct perf_hpp_list perf_hpp_list = {
535535
#undef __HPP_SORT_ACC_FN
536536
#undef __HPP_SORT_RAW_FN
537537

538+
static void fmt_free(struct perf_hpp_fmt *fmt)
539+
{
540+
/*
541+
* At this point fmt should be completely
542+
* unhooked, if not it's a bug.
543+
*/
544+
BUG_ON(!list_empty(&fmt->list));
545+
BUG_ON(!list_empty(&fmt->sort_list));
546+
547+
if (fmt->free)
548+
fmt->free(fmt);
549+
}
538550

539551
void perf_hpp__init(void)
540552
{
@@ -598,9 +610,10 @@ void perf_hpp_list__prepend_sort_field(struct perf_hpp_list *list,
598610
list_add(&format->sort_list, &list->sorts);
599611
}
600612

601-
void perf_hpp__column_unregister(struct perf_hpp_fmt *format)
613+
static void perf_hpp__column_unregister(struct perf_hpp_fmt *format)
602614
{
603615
list_del_init(&format->list);
616+
fmt_free(format);
604617
}
605618

606619
void perf_hpp__cancel_cumulate(void)
@@ -672,19 +685,6 @@ void perf_hpp__append_sort_keys(struct perf_hpp_list *list)
672685
}
673686

674687

675-
static void fmt_free(struct perf_hpp_fmt *fmt)
676-
{
677-
/*
678-
* At this point fmt should be completely
679-
* unhooked, if not it's a bug.
680-
*/
681-
BUG_ON(!list_empty(&fmt->list));
682-
BUG_ON(!list_empty(&fmt->sort_list));
683-
684-
if (fmt->free)
685-
fmt->free(fmt);
686-
}
687-
688688
void perf_hpp__reset_output_field(struct perf_hpp_list *list)
689689
{
690690
struct perf_hpp_fmt *fmt, *tmp;

‎tools/perf/util/hist.h‎

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -362,7 +362,6 @@ enum {
362362
};
363363

364364
void perf_hpp__init(void);
365-
void perf_hpp__column_unregister(struct perf_hpp_fmt *format);
366365
void perf_hpp__cancel_cumulate(void);
367366
void perf_hpp__setup_output_field(struct perf_hpp_list *list);
368367
void perf_hpp__reset_output_field(struct perf_hpp_list *list);

0 commit comments

Comments
 (0)