From: Malaya Kumar Rout <malayarout91@gmail.com>
To: malayarout91@gmail.com
Cc: Andrew Morton <akpm@linux-foundation.org>,
Shuah Khan <shuah@kernel.org>,
linux-mm@kvack.org, linux-kselftest@vger.kernel.org,
linux-kernel@vger.kernel.org
Subject: [PATCH v1] selftests/mm/cow: fix minor memory leak in child_vmsplice_memcmp_fn()
Date: Tue, 25 Mar 2025 23:52:55 +0530 [thread overview]
Message-ID: <20250325182319.29352-1-malayarout91@gmail.com> (raw)
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
next reply other threads:[~2025-03-25 18:23 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-03-25 18:22 Malaya Kumar Rout [this message]
2025-03-26 19:24 ` David Hildenbrand
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20250325182319.29352-1-malayarout91@gmail.com \
--to=malayarout91@gmail.com \
--cc=akpm@linux-foundation.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-kselftest@vger.kernel.org \
--cc=linux-mm@kvack.org \
--cc=shuah@kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox