Re: [PATCH] kunit: fix resource leak when init fails
From: Bartosz Golaszewski
Date: Thu Nov 19 2026 - 05:38:41 EST
On Wed, Nov 18, 2026 at 05:38:57PM +0800, Jiangshan Yi wrote:
> If the init function passed to kunit_alloc_resource() or
> kunit_alloc_and_get_resource() fails, __kunit_add_resource() returns
> before the resource is added to the test's resource list, so the
> allocated resource is never freed. Call kfree() on the error path.
>
> The free function is not called on this path: init() is responsible for
> cleaning up after a failure, and free() expects an initialized resource.
>
> Fixes: 0a756853586c ("kunit: test: add test resource management API")
> Cc: stable@xxxxxxxxxxxxxxx
> Signed-off-by: Jiangshan Yi <yijiangshan@xxxxxxxxxx>
> ---
Reviewed-by: Bartosz Golaszewski <bartosz.golaszewski@xxxxxxxxxxxxxxxx>