[PATCH] selftests/mm: Add missing free.

zhangjiao2 posted 1 patch 2 months ago
tools/testing/selftests/mm/mkdirty.c | 1 +
1 file changed, 1 insertion(+)
[PATCH] selftests/mm: Add missing free.
Posted by zhangjiao2 2 months ago
From: zhang jiao <zhangjiao2@cmss.chinamobile.com>

There is a memory leak in mkdirty, just free src before return.

Signed-off-by: zhang jiao <zhangjiao2@cmss.chinamobile.com>
---
 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.33.0
Re: [PATCH] selftests/mm: Add missing free.
Posted by David Hildenbrand 2 months ago
On 27.09.24 05:01, zhangjiao2 wrote:
> From: zhang jiao <zhangjiao2@cmss.chinamobile.com>
> 
> There is a memory leak in mkdirty, just free src before return.

Now explain to me why we care. The program will return immediately 
afterwards?

-- 
Cheers,

David / dhildenb
Re: [PATCH] selftests/mm: Add missing free.
Posted by Muhammad Usama Anjum 2 months ago
On 9/27/24 8:01 AM, zhangjiao2 wrote:
> From: zhang jiao <zhangjiao2@cmss.chinamobile.com>
> 
> There is a memory leak in mkdirty, just free src before return.
> 
> Signed-off-by: zhang jiao <zhangjiao2@cmss.chinamobile.com>
Please find the first patch which missed this free() and add fixes-by tag.

> ---
>  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;
>  	}
>  

-- 
BR,
Muhammad Usama Anjum