Linux Kernel Selftest development
 help / color / mirror / Atom feed
From: Yujie Liu <yujie.liu@intel.com>
To: David Gow <davidgow@google.com>
Cc: <kunit-dev@googlegroups.com>, <linux-kselftest@vger.kernel.org>,
	"Linux Kernel Mailing List" <linux-kernel@vger.kernel.org>,
	<llvm@lists.linux.dev>, Shuah Khan <skhan@linuxfoundation.org>,
	Brendan Higgins <brendanhiggins@google.com>,
	Daniel Latypov <dlatypov@google.com>
Subject: Re: [PATCH] kunit: executor: Fix a memory leak on failure in kunit_filter_tests
Date: Wed, 13 Jul 2022 01:54:41 +0800	[thread overview]
Message-ID: <db39a1c0-45e5-7458-00c5-87ebd56f3894@intel.com> (raw)
In-Reply-To: <20220712095627.1770312-1-davidgow@google.com>

Hi David,

On 7/12/2022 17:56, David Gow wrote:
> It's possible that memory allocation for the copy will fail, but for the

I think it is "for the _filtered_ will fail". Maybe a typo?

Thanks,
Yujie

> 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/
> 
> Fixes: a02353f49162 ("kunit: bail out of test filtering logic quicker if OOM")
> Reported-by: kernel test robot <yujie.liu@intel.com>
> Signed-off-by: David Gow <davidgow@google.com>
> ---
>   lib/kunit/executor.c | 4 +++-
>   1 file changed, 3 insertions(+), 1 deletion(-)
> 
> 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) {

  reply	other threads:[~2022-07-12 17:54 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-07-12  9:56 [PATCH] kunit: executor: Fix a memory leak on failure in kunit_filter_tests David Gow
2022-07-12 17:54 ` Yujie Liu [this message]
2022-07-12 21:27 ` Daniel Latypov
2022-07-12 21:30 ` Brendan Higgins

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=db39a1c0-45e5-7458-00c5-87ebd56f3894@intel.com \
    --to=yujie.liu@intel.com \
    --cc=brendanhiggins@google.com \
    --cc=davidgow@google.com \
    --cc=dlatypov@google.com \
    --cc=kunit-dev@googlegroups.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-kselftest@vger.kernel.org \
    --cc=llvm@lists.linux.dev \
    --cc=skhan@linuxfoundation.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox