lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [thread-next>] [day] [month] [year] [list]
Message-Id: <20240710073351.6479-1-zhujun2@cmss.chinamobile.com>
Date: Wed, 10 Jul 2024 00:33:51 -0700
From: Zhu Jun <zhujun2@...s.chinamobile.com>
To: shuah@...nel.org,
	akpm@...ux-foundation.org
Cc: cyphar@...har.com,
	jeffxu@...gle.com,
	sauravshah.31@...il.com,
	zhujun2@...s.chinamobile.com,
	gthelen@...gle.com,
	linux-kselftest@...r.kernel.org,
	linux-kernel@...r.kernel.org
Subject: [PATCH] selftests/memfd:Fix a resource leak

>From a good programming practice perspective, especially in more
complex programs, explicitly freeing allocated memory is a good habit.

Signed-off-by: Zhu Jun <zhujun2@...s.chinamobile.com>
---
 tools/testing/selftests/memfd/memfd_test.c | 7 +++++++
 1 file changed, 7 insertions(+)

diff --git a/tools/testing/selftests/memfd/memfd_test.c b/tools/testing/selftests/memfd/memfd_test.c
index 95af2d78fd31..f842a4aeb47d 100644
--- a/tools/testing/selftests/memfd/memfd_test.c
+++ b/tools/testing/selftests/memfd/memfd_test.c
@@ -661,9 +661,11 @@ static void mfd_assert_grow_write(int fd)
 	l = pwrite(fd, buf, mfd_def_size * 8, 0);
 	if (l != (mfd_def_size * 8)) {
 		printf("pwrite() failed: %m\n");
+		free(buf);
 		abort();
 	}
 
+	free(buf);
 	mfd_assert_size(fd, mfd_def_size * 8);
 }
 
@@ -685,8 +687,11 @@ static void mfd_fail_grow_write(int fd)
 	l = pwrite(fd, buf, mfd_def_size * 8, 0);
 	if (l == (mfd_def_size * 8)) {
 		printf("pwrite() didn't fail as expected\n");
+		free(buf);
 		abort();
 	}
+
+	free(buf);
 }
 
 static void mfd_assert_mode(int fd, int mode)
@@ -771,9 +776,11 @@ static pid_t spawn_thread(unsigned int flags, int (*fn)(void *), void *arg)
 	pid = clone(fn, stack + STACK_SIZE, SIGCHLD | flags, arg);
 	if (pid < 0) {
 		printf("clone() failed: %m\n");
+		free(stack);
 		abort();
 	}
 
+	free(stack);
 	return pid;
 }
 
-- 
2.17.1




Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ