linux-mm.kvack.org archive mirror
 help / color / mirror / Atom feed
* [PATCH v1] selftests/mm/cow: fix minor memory leak in child_vmsplice_memcmp_fn()
@ 2025-03-25 18:22 Malaya Kumar Rout
  2025-03-26 19:24 ` David Hildenbrand
  0 siblings, 1 reply; 2+ messages in thread
From: Malaya Kumar Rout @ 2025-03-25 18:22 UTC (permalink / raw)
  To: malayarout91
  Cc: Andrew Morton, Shuah Khan, linux-mm, linux-kselftest, linux-kernel

Static Analyis for cow.c: error
Exception branch exits without releasing memory 'old' and 'new'

fix the issue by releasing the allocated memory.

Signed-off-by: Malaya Kumar Rout <malayarout91@gmail.com>
---
 tools/testing/selftests/mm/cow.c | 13 +++++++++----
 1 file changed, 9 insertions(+), 4 deletions(-)

diff --git a/tools/testing/selftests/mm/cow.c b/tools/testing/selftests/mm/cow.c
index 9446673645eb..fdee42850548 100644
--- a/tools/testing/selftests/mm/cow.c
+++ b/tools/testing/selftests/mm/cow.c
@@ -168,18 +168,18 @@ static int child_vmsplice_memcmp_fn(char *mem, size_t size,
 	memcpy(old, mem, size);
 
 	if (pipe(fds) < 0)
-		return -errno;
+		goto out;
 
 	/* Trigger a read-only pin. */
 	transferred = vmsplice(fds[1], &iov, 1, 0);
 	if (transferred < 0)
-		return -errno;
+		goto out;
 	if (transferred == 0)
 		return -EINVAL;
 
 	/* Unmap it from our page tables. */
 	if (munmap(mem, size) < 0)
-		return -errno;
+		goto out;
 
 	/* Wait until the parent modified it. */
 	write(comm_pipes->child_ready[1], "0", 1);
@@ -190,10 +190,15 @@ static int child_vmsplice_memcmp_fn(char *mem, size_t size,
 	for (total = 0; total < transferred; total += cur) {
 		cur = read(fds[0], new + total, transferred - total);
 		if (cur < 0)
-			return -errno;
+			goto out;
 	}
 
 	return memcmp(old, new, transferred);
+
+out:
+	free(old);
+	free(new);
+	return -errno;
 }
 
 typedef int (*child_fn)(char *mem, size_t size, struct comm_pipes *comm_pipes);
-- 
2.43.0



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

* Re: [PATCH v1] selftests/mm/cow: fix minor memory leak in child_vmsplice_memcmp_fn()
  2025-03-25 18:22 [PATCH v1] selftests/mm/cow: fix minor memory leak in child_vmsplice_memcmp_fn() Malaya Kumar Rout
@ 2025-03-26 19:24 ` David Hildenbrand
  0 siblings, 0 replies; 2+ messages in thread
From: David Hildenbrand @ 2025-03-26 19:24 UTC (permalink / raw)
  To: Malaya Kumar Rout
  Cc: Andrew Morton, Shuah Khan, linux-mm, linux-kselftest, linux-kernel

On 25.03.25 19:22, Malaya Kumar Rout wrote:
> Static Analyis for cow.c: error
> Exception branch exits without releasing memory 'old' and 'new'
> 
> fix the issue by releasing the allocated memory.
> 
> Signed-off-by: Malaya Kumar Rout <malayarout91@gmail.com>
> ---

https://lore.kernel.org/linux-mm/20230404031256.78330-1-jiangfeng@kylinos.cn/

-- 
Cheers,

David / dhildenb



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

end of thread, other threads:[~2025-03-26 19:24 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2025-03-25 18:22 [PATCH v1] selftests/mm/cow: fix minor memory leak in child_vmsplice_memcmp_fn() Malaya Kumar Rout
2025-03-26 19:24 ` David Hildenbrand

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