Re: [PATCH] selftests/cgroup: Add NULL check after malloc in cgroup_util.c
From: Vishal Moola
Date: Mon May 11 2026 - 08:05:07 EST
On Mon, May 11, 2026 at 02:08:53PM +0800, Hongfu Li wrote:
> Add NULL checks after malloc() in three helper functions to prevent
> NULL pointer dereference on memory allocation failure.
> - cg_name()
> - cg_name_indexed()
> - cg_control()
>
> These functions allocate memory with malloc() but previously called
> snprintf() unconditionally, which would trigger undefined behavior
> if allocation fails.
>
> Signed-off-by: Hongfu Li <lihongfu@xxxxxxxxxx>
> ---
Reviewed-by: Vishal Moola <vishal.moola@xxxxxxxxx>