diff options
author | David Gow <[email protected]> | 2022-07-13 07:25:27 +0800 |
---|---|---|
committer | Shuah Khan <[email protected]> | 2022-07-14 10:35:56 -0600 |
commit | 94681e289bf5d10c9db9db143d1a22d8717205c5 (patch) | |
tree | 1527d608eeed9d93ca121ac8eb785cdfbc9478ac | |
parent | f84a9e9658337e5a8407819971c79fd97bb7d408 (diff) |
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/[email protected]/
And by smatch via Dan Carpenter and the kernel test robot:
https://lore.kernel.org/all/[email protected]/
Fixes: a02353f49162 ("kunit: bail out of test filtering logic quicker if OOM")
Reported-by: kernel test robot <[email protected]>
Reported-by: kernel test robot <[email protected]>
Reported-by: Dan Carpenter <[email protected]>
Reviewed-by: Daniel Latypov <[email protected]>
Reviewed-by: Brendan Higgins <[email protected]>
Signed-off-by: David Gow <[email protected]>
Signed-off-by: Shuah Khan <[email protected]>
-rw-r--r-- | lib/kunit/executor.c | 4 |
1 files changed, 3 insertions, 1 deletions
diff --git a/lib/kunit/executor.c b/lib/kunit/executor.c index 6c489d6c5e5d..5e223327196a 100644 --- a/lib/kunit/executor.c +++ b/lib/kunit/executor.c @@ -74,8 +74,10 @@ kunit_filter_tests(const struct kunit_suite *const suite, const char *test_glob) return ERR_PTR(-ENOMEM); filtered = kcalloc(n + 1, sizeof(*filtered), GFP_KERNEL); - if (!filtered) + if (!filtered) { + kfree(copy); return ERR_PTR(-ENOMEM); + } n = 0; kunit_suite_for_each_test_case(suite, test_case) { |