Re: [PATCH] selftests/mm: read memory information without popen
From: Mike Rapoport
Date: Tue Aug 04 2026 - 05:59:52 EST
On Mon, Aug 03, 2026 at 09:30:15AM +0800, Warren Xiong wrote:
> read_memory_info() invokes two shell pipelines to obtain MemFree and
> Hugepagesize from /proc/meminfo. It does not check whether popen()
> returns NULL before passing the result to fgets(), and it does not call
> pclose() when fgets() fails.
>
> Open /proc/meminfo directly and obtain both values in a single pass.
> This removes the unchecked NULL path, closes the file on all paths, and
> avoids dependencies on external commands.
>
> The compaction test continues to pass after this change.
>
> Signed-off-by: Warren Xiong <warren.xiong@xxxxxxxxxx>
Acked-by: Mike Rapoport (Microsoft) <rppt@xxxxxxxxxx>
> ---
> tools/testing/selftests/mm/compaction_test.c | 43 +++++++++++++++++-----------
> 1 file changed, 27 insertions(+), 16 deletions(-)
--
Sincerely yours,
Mike.