Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

perf hist: Fix memory leak of a perf_hpp_fmt

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>

authored by

Ian Rogers and committed by
Arnaldo Carvalho de Melo
0ca1f534 8b8dcc37

+14 -15
+14 -14
tools/perf/ui/hist.c
··· 535 535 #undef __HPP_SORT_ACC_FN 536 536 #undef __HPP_SORT_RAW_FN 537 537 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 + } 538 550 539 551 void perf_hpp__init(void) 540 552 { ··· 610 598 list_add(&format->sort_list, &list->sorts); 611 599 } 612 600 613 - void perf_hpp__column_unregister(struct perf_hpp_fmt *format) 601 + static void perf_hpp__column_unregister(struct perf_hpp_fmt *format) 614 602 { 615 603 list_del_init(&format->list); 604 + fmt_free(format); 616 605 } 617 606 618 607 void perf_hpp__cancel_cumulate(void) ··· 684 671 } 685 672 } 686 673 687 - 688 - static void fmt_free(struct perf_hpp_fmt *fmt) 689 - { 690 - /* 691 - * At this point fmt should be completely 692 - * unhooked, if not it's a bug. 693 - */ 694 - BUG_ON(!list_empty(&fmt->list)); 695 - BUG_ON(!list_empty(&fmt->sort_list)); 696 - 697 - if (fmt->free) 698 - fmt->free(fmt); 699 - } 700 674 701 675 void perf_hpp__reset_output_field(struct perf_hpp_list *list) 702 676 {
-1
tools/perf/util/hist.h
··· 369 369 }; 370 370 371 371 void perf_hpp__init(void); 372 - void perf_hpp__column_unregister(struct perf_hpp_fmt *format); 373 372 void perf_hpp__cancel_cumulate(void); 374 373 void perf_hpp__setup_output_field(struct perf_hpp_list *list); 375 374 void perf_hpp__reset_output_field(struct perf_hpp_list *list);