]> git.baikalelectronics.ru Git - kernel.git/commit
kunit: executor: Fix a memory leak on failure in kunit_filter_tests
authorDavid Gow <davidgow@google.com>
Tue, 12 Jul 2022 23:25:27 +0000 (07:25 +0800)
committerShuah Khan <skhan@linuxfoundation.org>
Thu, 14 Jul 2022 16:35:56 +0000 (10:35 -0600)
commit70560af7c7d0ff7a0f43a530ab18b2afe2e7b147
tree1527d608eeed9d93ca121ac8eb785cdfbc9478ac
parent9f50d500feb37d510c5a39a96ef39f92adc76c75
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: 9162d3b3a529 ("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>
lib/kunit/executor.c