perf hist: Fix memory leak of a perf_hpp_fmt
Ian Rogers
reviewerPATCH 1/1 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.
--- tools/perf/ui/hist.c | 28 ++++++++++++++-------------- tools/perf/util/hist.h | 1 - 2 files changed, 14 insertions(+), 15 deletions(-)
tools/perf/ui/hist.c +14 -14
@@ -535,6 +535,18 @@ struct perf_hpp_list perf_hpp_list = {#undef __HPP_SORT_ACC_FN#undef __HPP_SORT_RAW_FN +static void fmt_free (struct perf_hpp_fmt *fmt) +{ +/* +* At this point fmt should be completely +* unhooked, if not it's a bug. +*/ +BUG_ON (!list_empty (&fmt->list)); +BUG_ON (!list_empty (&fmt->sort_list)); + +if (fmt->free) + fmt->free (fmt); +}void perf_hpp__init (void ) {
@@ -598,9 +610,10 @@ void perf_hpp_list__prepend_sort_field(struct perf_hpp_list *list,list_add (&format->sort_list, &list->sorts); } -void perf_hpp__column_unregister (struct perf_hpp_fmt *format) +static void perf_hpp__column_unregister (struct perf_hpp_fmt *format) {list_del_init (&format->list); +fmt_free (format); }void perf_hpp__cancel_cumulate (void )
@@ -672,19 +685,6 @@ void perf_hpp__append_sort_keys(struct perf_hpp_list *list) } -static void fmt_free (struct perf_hpp_fmt *fmt) -{ -/* -* At this point fmt should be completely -* unhooked, if not it's a bug. -*/ -BUG_ON (!list_empty (&fmt->list)); -BUG_ON (!list_empty (&fmt->sort_list)); - -if (fmt->free) - fmt->free (fmt); -} -void perf_hpp__reset_output_field (struct perf_hpp_list *list) {struct perf_hpp_fmt *fmt, *tmp;
tools/perf/util/hist.h +0 -1
@@ -369,7 +369,6 @@ enum { };void perf_hpp__init (void ); -void perf_hpp__column_unregister (struct perf_hpp_fmt *format);void perf_hpp__cancel_cumulate (void );void perf_hpp__setup_output_field (struct perf_hpp_list *list);void perf_hpp__reset_output_field (struct perf_hpp_list *list);
Signature · 1 line
2.34.0.rc1.387.gb447b232ab-goog
Quoted 4 lines · Ian Rogers
perf_hpp__column_unregisterremoves 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.
Patch looks good to me.
Thanks,
Kajol jain
Quoted 75 lines
Signed-off-by Ian Rogers <[email protected]>--- tools/perf/ui/hist.c | 28 ++++++++++++++-------------- tools/perf/util/hist.h | 1 - 2 files changed, 14 insertions(+), 15 deletions(-)tools/perf/ui/hist.c +14
-14@@ -535,6 +535,18 @@ struct perf_hpp_list perf_hpp_list = {#undef __HPP_SORT_ACC_FN#undef __HPP_SORT_RAW_FN +static void fmt_free (struct perf_hpp_fmt *fmt) +{ +/* +* At this point fmt should be completely +* unhooked, if not it's a bug. +*/ +BUG_ON (!list_empty (&fmt->list)); +BUG_ON (!list_empty (&fmt->sort_list)); + +if (fmt->free) + fmt->free (fmt); +}void perf_hpp__init (void ) {@@ -598,9 +610,10 @@ void perf_hpp_list__prepend_sort_field(struct perf_hpp_list *list,list_add (&format->sort_list, &list->sorts); } -void perf_hpp__column_unregister (struct perf_hpp_fmt *format) +static void perf_hpp__column_unregister (struct perf_hpp_fmt *format) {list_del_init (&format->list); +fmt_free (format); }void perf_hpp__cancel_cumulate (void )@@ -672,19 +685,6 @@ void perf_hpp__append_sort_keys(struct perf_hpp_list *list) } -static void fmt_free (struct perf_hpp_fmt *fmt) -{ -/* -* At this point fmt should be completely -* unhooked, if not it's a bug. -*/ -BUG_ON (!list_empty (&fmt->list)); -BUG_ON (!list_empty (&fmt->sort_list)); - -if (fmt->free) - fmt->free (fmt); -} -void perf_hpp__reset_output_field (struct perf_hpp_list *list) {struct perf_hpp_fmt *fmt, *tmp;tools/perf/util/hist.h +0
-1@@ -369,7 +369,6 @@ enum { };void perf_hpp__init (void ); -void perf_hpp__column_unregister (struct perf_hpp_fmt *format);void perf_hpp__cancel_cumulate (void );void perf_hpp__setup_output_field (struct perf_hpp_list *list);void perf_hpp__reset_output_field (struct perf_hpp_list *list);
Em Thu, Nov 18, 2021 at 01:28:11PM +0530, kajoljain escreveu:
Quoted 11 lines · Ian Rogers
Quoted 4 lines
perf_hpp__column_unregisterremoves 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.Patch looks good to me.
Reviewed-by Kajol Jain<[email protected]>
Thanks, applied.
- Arnaldo
Quoted 78 lines
Thanks,
Kajol jainQuoted 75 lines
Signed-off-by Ian Rogers <[email protected]>--- tools/perf/ui/hist.c | 28 ++++++++++++++-------------- tools/perf/util/hist.h | 1 - 2 files changed, 14 insertions(+), 15 deletions(-)tools/perf/ui/hist.c +14
-14@@ -535,6 +535,18 @@ struct perf_hpp_list perf_hpp_list = {#undef __HPP_SORT_ACC_FN#undef __HPP_SORT_RAW_FN +static void fmt_free (struct perf_hpp_fmt *fmt) +{ +/* +* At this point fmt should be completely +* unhooked, if not it's a bug. +*/ +BUG_ON (!list_empty (&fmt->list)); +BUG_ON (!list_empty (&fmt->sort_list)); + +if (fmt->free) + fmt->free (fmt); +}void perf_hpp__init (void ) {@@ -598,9 +610,10 @@ void perf_hpp_list__prepend_sort_field(struct perf_hpp_list *list,list_add (&format->sort_list, &list->sorts); } -void perf_hpp__column_unregister (struct perf_hpp_fmt *format) +static void perf_hpp__column_unregister (struct perf_hpp_fmt *format) {list_del_init (&format->list); +fmt_free (format); }void perf_hpp__cancel_cumulate (void )@@ -672,19 +685,6 @@ void perf_hpp__append_sort_keys(struct perf_hpp_list *list) } -static void fmt_free (struct perf_hpp_fmt *fmt) -{ -/* -* At this point fmt should be completely -* unhooked, if not it's a bug. -*/ -BUG_ON (!list_empty (&fmt->list)); -BUG_ON (!list_empty (&fmt->sort_list)); - -if (fmt->free) - fmt->free (fmt); -} -void perf_hpp__reset_output_field (struct perf_hpp_list *list) {struct perf_hpp_fmt *fmt, *tmp;tools/perf/util/hist.h +0
-1@@ -369,7 +369,6 @@ enum { };void perf_hpp__init (void ); -void perf_hpp__column_unregister (struct perf_hpp_fmt *format);void perf_hpp__cancel_cumulate (void );void perf_hpp__setup_output_field (struct perf_hpp_list *list);void perf_hpp__reset_output_field (struct perf_hpp_list *list);
Signature · 1 line
- Arnaldo