Skip to content

Commit 94681e2

Browse files
sulixshuahkh
authored andcommitted
kunit: executor: Fix a memory leak on failure in kunit_filter_tests
It's possible that memory allocation for 'filtered' will fail, but for the copy of the suite to succeed. In this case, the copy could be leaked. Properly free 'copy' in the error case for the allocation of 'filtered' failing. Note that there may also have been a similar issue in kunit_filter_subsuites, before it was removed in "kunit: flatten kunit_suite*** to kunit_suite** in .kunit_test_suites". This was reported by clang-analyzer via the kernel test robot, here: https://lore.kernel.org/all/c8073b8e-7b9e-0830-4177-87c12f16349c@intel.com/ And by smatch via Dan Carpenter and the kernel test robot: https://lore.kernel.org/all/202207101328.ASjx88yj-lkp@intel.com/ Fixes: a02353f ("kunit: bail out of test filtering logic quicker if OOM") Reported-by: kernel test robot <yujie.liu@intel.com> Reported-by: kernel test robot <lkp@intel.com> Reported-by: Dan Carpenter <dan.carpenter@oracle.com> Reviewed-by: Daniel Latypov <dlatypov@google.com> Reviewed-by: Brendan Higgins <brendanhiggins@google.com> Signed-off-by: David Gow <davidgow@google.com> Signed-off-by: Shuah Khan <skhan@linuxfoundation.org>
1 parent f84a9e9 commit 94681e2

1 file changed

Lines changed: 3 additions & 1 deletion

File tree

lib/kunit/executor.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,8 +74,10 @@ kunit_filter_tests(const struct kunit_suite *const suite, const char *test_glob)
7474
return ERR_PTR(-ENOMEM);
7575

7676
filtered = kcalloc(n + 1, sizeof(*filtered), GFP_KERNEL);
77-
if (!filtered)
77+
if (!filtered) {
78+
kfree(copy);
7879
return ERR_PTR(-ENOMEM);
80+
}
7981

8082
n = 0;
8183
kunit_suite_for_each_test_case(suite, test_case) {

0 commit comments

Comments
 (0)