public inbox for [email protected]
 help / color / mirror / Atom feed
* [ammarfaizi2-block:shuah/linux-kselftest/kunit 4/16] lib/kunit/executor.c:78 kunit_filter_tests() warn: possible memory leak of 'copy'
@ 2022-07-12 12:50 Dan Carpenter
  2022-07-12 13:29 ` David Gow
  0 siblings, 1 reply; 2+ messages in thread
From: Dan Carpenter @ 2022-07-12 12:50 UTC (permalink / raw)
  To: kbuild, Daniel Latypov
  Cc: lkp, kbuild-all, GNU/Weeb Mailing List, linux-kernel, Shuah Khan,
	David Gow, Brendan Higgins

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/[email protected]/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 <[email protected]>
Reported-by: Dan Carpenter <[email protected]>

smatch warnings:
lib/kunit/executor.c:78 kunit_filter_tests() warn: possible memory leak of 'copy'

vim +/copy +78 lib/kunit/executor.c

a127b154a8f2317 Daniel Latypov 2021-09-14  57  static struct kunit_suite *
d2fbdde838f2703 Daniel Latypov 2022-05-16  58  kunit_filter_tests(const struct kunit_suite *const suite, const char *test_glob)
a127b154a8f2317 Daniel Latypov 2021-09-14  59  {
a127b154a8f2317 Daniel Latypov 2021-09-14  60  	int n = 0;
a127b154a8f2317 Daniel Latypov 2021-09-14  61  	struct kunit_case *filtered, *test_case;
a127b154a8f2317 Daniel Latypov 2021-09-14  62  	struct kunit_suite *copy;
a127b154a8f2317 Daniel Latypov 2021-09-14  63  
a127b154a8f2317 Daniel Latypov 2021-09-14  64  	kunit_suite_for_each_test_case(suite, test_case) {
a127b154a8f2317 Daniel Latypov 2021-09-14  65  		if (!test_glob || glob_match(test_glob, test_case->name))
a127b154a8f2317 Daniel Latypov 2021-09-14  66  			++n;
a127b154a8f2317 Daniel Latypov 2021-09-14  67  	}
a127b154a8f2317 Daniel Latypov 2021-09-14  68  
a127b154a8f2317 Daniel Latypov 2021-09-14  69  	if (n == 0)
a127b154a8f2317 Daniel Latypov 2021-09-14  70  		return NULL;
a127b154a8f2317 Daniel Latypov 2021-09-14  71  
d2fbdde838f2703 Daniel Latypov 2022-05-16  72  	copy = kmemdup(suite, sizeof(*copy), GFP_KERNEL);
a02353f491622e4 Daniel Latypov 2022-05-11  73  	if (!copy)
a02353f491622e4 Daniel Latypov 2022-05-11  74  		return ERR_PTR(-ENOMEM);
a127b154a8f2317 Daniel Latypov 2021-09-14  75  
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.

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  }

-- 
0-DAY CI Kernel Test Service
https://01.org/lkp


^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: [ammarfaizi2-block:shuah/linux-kselftest/kunit 4/16] lib/kunit/executor.c:78 kunit_filter_tests() warn: possible memory leak of 'copy'
  2022-07-12 12:50 [ammarfaizi2-block:shuah/linux-kselftest/kunit 4/16] lib/kunit/executor.c:78 kunit_filter_tests() warn: possible memory leak of 'copy' Dan Carpenter
@ 2022-07-12 13:29 ` David Gow
  0 siblings, 0 replies; 2+ messages in thread
From: David Gow @ 2022-07-12 13:29 UTC (permalink / raw)
  To: Dan Carpenter
  Cc: kbuild, Daniel Latypov, kernel test robot, kbuild-all,
	GNU/Weeb Mailing List, Linux Kernel Mailing List, Shuah Khan,
	Brendan Higgins

On Tue, Jul 12, 2022 at 8:51 PM Dan Carpenter <[email protected]> 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/[email protected]/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 <[email protected]>
> Reported-by: Dan Carpenter <[email protected]>
>
> 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/[email protected]/

(... 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/[email protected]/

> 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

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2022-07-12 13:30 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2022-07-12 12:50 [ammarfaizi2-block:shuah/linux-kselftest/kunit 4/16] lib/kunit/executor.c:78 kunit_filter_tests() warn: possible memory leak of 'copy' Dan Carpenter
2022-07-12 13:29 ` David Gow

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox