[<prev] [next>] [<thread-prev] [day] [month] [year] [list]
Message-ID: <CABVgOSmvU1tOHBQDOr9vT-SSaM1k--mjck1-T-M_vWnDtWecDA@mail.gmail.com>
Date: Tue, 12 Jul 2022 21:29:55 +0800
From: David Gow <davidgow@...gle.com>
To: Dan Carpenter <dan.carpenter@...cle.com>
Cc: kbuild@...ts.01.org, Daniel Latypov <dlatypov@...gle.com>,
kernel test robot <lkp@...el.com>, kbuild-all@...ts.01.org,
"GNU/Weeb Mailing List" <gwml@...r.gnuweeb.org>,
Linux Kernel Mailing List <linux-kernel@...r.kernel.org>,
Shuah Khan <skhan@...uxfoundation.org>,
Brendan Higgins <brendanhiggins@...gle.com>
Subject: Re: [ammarfaizi2-block:shuah/linux-kselftest/kunit 4/16]
lib/kunit/executor.c:78 kunit_filter_tests() warn: possible memory leak of 'copy'
On Tue, Jul 12, 2022 at 8:51 PM Dan Carpenter <dan.carpenter@...cle.com> wrote:
>
> tree: https://github.com/ammarfaizi2/linux-block shuah/linux-kselftest/kunit
> head: 7635778bac7e46458392c1261e3916e8e9e86860
> commit: d2fbdde838f270377de4fc20e919aac3941ea55f [4/16] kunit: use kmemdup in kunit_filter_tests(), take suite as const
> config: arc-randconfig-m031-20220707 (https://download.01.org/0day-ci/archive/20220710/202207101328.ASjx88yj-lkp@intel.com/config)
> compiler: arc-elf-gcc (GCC) 11.3.0
>
> If you fix the issue, kindly add following tag where applicable
> Reported-by: kernel test robot <lkp@...el.com>
> Reported-by: Dan Carpenter <dan.carpenter@...cle.com>
>
> smatch warnings:
> lib/kunit/executor.c:78 kunit_filter_tests() warn: possible memory leak of 'copy'
>
> vim +/copy +78 lib/kunit/executor.c
Thanks: clang-analyzer also picked this up here:
https://lore.kernel.org/all/c8073b8e-7b9e-0830-4177-87c12f16349c@intel.com/
(... snip ...)
> a127b154a8f2317 Daniel Latypov 2021-09-14 76 filtered = kcalloc(n + 1, sizeof(*filtered), GFP_KERNEL);
> a02353f491622e4 Daniel Latypov 2022-05-11 77 if (!filtered)
> a02353f491622e4 Daniel Latypov 2022-05-11 @78 return ERR_PTR(-ENOMEM);
>
> kfree(copy)? Is the burden of random devs looking at this warning
> forever more than the burden of adding a kfree()? Hard to measure.
>
I mean, it's the burden of not only adding a kfree(), but also a
couple of {}s. :-)
Regardless, this patch should add them:
https://lore.kernel.org/linux-kselftest/20220712095627.1770312-1-davidgow@google.com/
> a127b154a8f2317 Daniel Latypov 2021-09-14 79
> a127b154a8f2317 Daniel Latypov 2021-09-14 80 n = 0;
> a127b154a8f2317 Daniel Latypov 2021-09-14 81 kunit_suite_for_each_test_case(suite, test_case) {
> a127b154a8f2317 Daniel Latypov 2021-09-14 82 if (!test_glob || glob_match(test_glob, test_case->name))
> a127b154a8f2317 Daniel Latypov 2021-09-14 83 filtered[n++] = *test_case;
> a127b154a8f2317 Daniel Latypov 2021-09-14 84 }
> a127b154a8f2317 Daniel Latypov 2021-09-14 85
> a127b154a8f2317 Daniel Latypov 2021-09-14 86 copy->test_cases = filtered;
> a127b154a8f2317 Daniel Latypov 2021-09-14 87 return copy;
> a127b154a8f2317 Daniel Latypov 2021-09-14 88 }
>
Cheers,
-- David
Powered by blists - more mailing lists