Re: [PATCH v3] tools/mm/page_owner_sort: free per-record allocations
From: Andrew Morton
Date: Thu Jun 25 2026 - 20:19:49 EST
On Fri, 12 Jun 2026 13:50:17 +0800 Yichong Chen <chenyichong@xxxxxxxxxxxxx> wrote:
>
(how come so may people are working on page_owner lately?)
>
> add_list() allocates comm and txt for each page owner record, but the
> cleanup path only frees the outer list array. This leaks both buffers for
> every retained record.
>
> Free partial allocations in add_list(), discarded records during
> culling, and retained records on exit. Return explicit error, skip, and
> match results from filter_record() to handle get_comm() failures.
Well gee, there's a very reliable way of freeing all the allocated
memory and there's a syscall for the purpose - exit()!
Really, everything below the "out_free:" label in main() can just be
deleted.
But oh well, the code does make an attempt to clean up after itself so
I guess we should set a good example. Thanks.
btw, AI review flagged another (pre-existing) issue which we normally
wouldn't care about:
https://sashiko.dev/#/patchset/610C3A89A09303F8+20260612055017.632263-1-chenyichong@xxxxxxxxxxxxx