linux-mm.kvack.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] selftests/mm/mkdirty: Fix memory leak in test_uffdio_copy()
@ 2025-01-14  2:38 liuye
  2025-01-14 10:21 ` David Hildenbrand
  0 siblings, 1 reply; 2+ messages in thread
From: liuye @ 2025-01-14  2:38 UTC (permalink / raw)
  To: akpm, shuah; +Cc: linux-mm, linux-kselftest, linux-kernel, liuye

    Release memory before exception branch returns to prevent memory leaks

Checking tools/testing/selftests/mm/mkdirty.c ...
tools/testing/selftests/mm/mkdirty.c:283:3: error: Memory leak: src [memleak]
  return;
  ^

Signed-off-by: liuye <liuye@kylinos.cn>
---
 tools/testing/selftests/mm/mkdirty.c | 1 +
 1 file changed, 1 insertion(+)

diff --git a/tools/testing/selftests/mm/mkdirty.c b/tools/testing/selftests/mm/mkdirty.c
index 1db134063c38..af2fce496912 100644
--- a/tools/testing/selftests/mm/mkdirty.c
+++ b/tools/testing/selftests/mm/mkdirty.c
@@ -280,6 +280,7 @@ static void test_uffdio_copy(void)
 	dst = mmap(NULL, pagesize, PROT_READ, MAP_PRIVATE|MAP_ANON, -1, 0);
 	if (dst == MAP_FAILED) {
 		ksft_test_result_fail("mmap() failed\n");
+		free(src);
 		return;
 	}
 
-- 
2.25.1



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

* Re: [PATCH] selftests/mm/mkdirty: Fix memory leak in test_uffdio_copy()
  2025-01-14  2:38 [PATCH] selftests/mm/mkdirty: Fix memory leak in test_uffdio_copy() liuye
@ 2025-01-14 10:21 ` David Hildenbrand
  0 siblings, 0 replies; 2+ messages in thread
From: David Hildenbrand @ 2025-01-14 10:21 UTC (permalink / raw)
  To: liuye, akpm, shuah; +Cc: linux-mm, linux-kselftest, linux-kernel

On 14.01.25 03:38, liuye wrote:
>      Release memory before exception branch returns to prevent memory leaks
> 
> Checking tools/testing/selftests/mm/mkdirty.c ...
> tools/testing/selftests/mm/mkdirty.c:283:3: error: Memory leak: src [memleak]
>    return;
>    ^

Don't take this the wrong way: there must be something better to be done 
with your time than fixing memory leaks on exit paths in tests.

> 
> Signed-off-by: liuye <liuye@kylinos.cn>
> ---
>   tools/testing/selftests/mm/mkdirty.c | 1 +
>   1 file changed, 1 insertion(+)
> 
> diff --git a/tools/testing/selftests/mm/mkdirty.c b/tools/testing/selftests/mm/mkdirty.c
> index 1db134063c38..af2fce496912 100644
> --- a/tools/testing/selftests/mm/mkdirty.c
> +++ b/tools/testing/selftests/mm/mkdirty.c
> @@ -280,6 +280,7 @@ static void test_uffdio_copy(void)
>   	dst = mmap(NULL, pagesize, PROT_READ, MAP_PRIVATE|MAP_ANON, -1, 0);
>   	if (dst == MAP_FAILED) {
>   		ksft_test_result_fail("mmap() failed\n");
> +		free(src);


We are immediately exiting the test afterwards ...

In any case, the change LGTM

Reviewed-by: David Hildenbrand <david@redhat.com>

-- 
Cheers,

David / dhildenb



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

end of thread, other threads:[~2025-01-14 10:21 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2025-01-14  2:38 [PATCH] selftests/mm/mkdirty: Fix memory leak in test_uffdio_copy() liuye
2025-01-14 10:21 ` David Hildenbrand

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