Re: [PATCH v2] selftests/mm: mlock2-tests: fix fclose(NULL) in is_vmflag_set()

From: David Hildenbrand (Arm)

Date: Fri Nov 13 2026 - 09:21:39 EST


On 11/13/26 03:52, Hongfu Li wrote:
> is_vmflag_set() jumps to the shared 'out' label when
> seek_to_smaps_entry() fails. smaps is NULL on that path, and the
> code at the 'out' label calls fclose(smaps) unconditionally.
> fclose(NULL) is undefined behaviour, so the test crashes before
> it can report a test result.

I was briefly confuses staring at get_value_for_name() diff below. WHich is
clarified below.

>
> Return early on that error path instead, so smaps is always valid
> at the 'out' label.
>
> get_value_for_name() follows the same pattern. Return early on the
> seek_to_smaps_entry() error path there as well, and drop the now
> redundant 'if (smaps)' guard on the fclose().
>
> Signed-off-by: Hongfu Li <lihongfu@xxxxxxxxxx>

Fixes: tag? :)

Apart form that LGTM

Reviewed-by: David Hildenbrand (Arm) <david@xxxxxxxxxx>

--
Cheers,

David