Re: [PATCH] selftests/mm/cow : Fix memory leak in child_vmsplice_memcmp_fn()

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On 14.01.25 03:29, liuye wrote:
     Release memory before exception branch returns to prevent memory leaks.

Signed-off-by: liuye <liuye@xxxxxxxxxx>
---
  tools/testing/selftests/mm/cow.c | 21 ++++++++++++++++-----
  1 file changed, 16 insertions(+), 5 deletions(-)

diff --git a/tools/testing/selftests/mm/cow.c b/tools/testing/selftests/mm/cow.c
index 1238e1c5aae1..959327ba6258 100644
--- a/tools/testing/selftests/mm/cow.c
+++ b/tools/testing/selftests/mm/cow.c
@@ -167,19 +167,30 @@ static int child_vmsplice_memcmp_fn(char *mem, size_t size,
  	/* Backup the original content. */
  	memcpy(old, mem, size);
- if (pipe(fds) < 0)
+	if (pipe(fds) < 0) {
+		free(old);
+		free(new);
  		return -errno;
-
+	}
  	/* Trigger a read-only pin. */
  	transferred = vmsplice(fds[1], &iov, 1, 0);
-	if (transferred < 0)
+	if (transferred < 0) {
+		free(old);
+		free(new);
  		return -errno;
-	if (transferred == 0)
+	}
+	if (transferred == 0) {
+		free(old);
+		free(new);
  		return -EINVAL;
+	}
/* Unmap it from our page tables. */
-	if (munmap(mem, size) < 0)
+	if (munmap(mem, size) < 0) {
+		free(old);
+		free(new);
  		return -errno;
+	}

We are immediately exiting the test in do_test_cow_in_parent()
	exit(fn(mem, size, &comm_pipes));

Your changes make the code unnecessarily more complicated to read, so I'm not in favor of this one to make some checker tool happy.

--
Cheers,

David / dhildenb





[Index of Archives]     [Linux Wireless]     [Linux Kernel]     [ATH6KL]     [Linux Bluetooth]     [Linux Netdev]     [Kernel Newbies]     [Share Photos]     [IDE]     [Security]     [Git]     [Netfilter]     [Bugtraq]     [Yosemite News]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Linux ATA RAID]     [Samba]     [Device Mapper]

  Powered by Linux