From: Malaya Kumar Rout <malayarout91@gmail.com>
To: mingo@kernel.org
Cc: Malaya Kumar Rout <malayarout91@gmail.com>,
Thomas Gleixner <tglx@linutronix.de>,
Ingo Molnar <mingo@redhat.com>, Borislav Petkov <bp@alien8.de>,
Dave Hansen <dave.hansen@linux.intel.com>,
x86@kernel.org, "H. Peter Anvin" <hpa@zytor.com>,
Shuah Khan <shuah@kernel.org>,
linux-kernel@vger.kernel.org, linux-kselftest@vger.kernel.org
Subject: [PATCH v2] selftests/x86/lam: fix resource leak in do_uring() and allocate_dsa_pasid()
Date: Mon, 7 Apr 2025 16:14:44 +0530 [thread overview]
Message-ID: <20250407104445.442876-1-malayarout91@gmail.com> (raw)
In-Reply-To: <CAE2+fR_kG1SpE3DZ6cbZL+J8HT25RcaGxYrZP-H+rDFSJG6sdQ@mail.gmail.com>
Exception branch returns without closing
the file descriptors 'file_fd' and 'fd'
Signed-off-by: Malaya Kumar Rout <malayarout91@gmail.com>
:wq
---
tools/testing/selftests/x86/lam.c | 13 ++++++++-----
1 file changed, 8 insertions(+), 5 deletions(-)
diff --git a/tools/testing/selftests/x86/lam.c b/tools/testing/selftests/x86/lam.c
index 18d736640ece..1d3631ce4b69 100644
--- a/tools/testing/selftests/x86/lam.c
+++ b/tools/testing/selftests/x86/lam.c
@@ -682,7 +682,7 @@ int do_uring(unsigned long lam)
return 1;
if (fstat(file_fd, &st) < 0)
- return 1;
+ goto cleanup;
off_t file_sz = st.st_size;
@@ -690,7 +690,7 @@ int do_uring(unsigned long lam)
fi = malloc(sizeof(*fi) + sizeof(struct iovec) * blocks);
if (!fi)
- return 1;
+ goto cleanup;
fi->file_sz = file_sz;
fi->file_fd = file_fd;
@@ -698,7 +698,7 @@ int do_uring(unsigned long lam)
ring = malloc(sizeof(*ring));
if (!ring) {
free(fi);
- return 1;
+ goto cleanup;
}
memset(ring, 0, sizeof(struct io_ring));
@@ -729,6 +729,8 @@ int do_uring(unsigned long lam)
}
free(fi);
+cleanup:
+ close(file_fd);
return ret;
}
@@ -1189,9 +1191,10 @@ void *allocate_dsa_pasid(void)
wq = mmap(NULL, 0x1000, PROT_WRITE,
MAP_SHARED | MAP_POPULATE, fd, 0);
- if (wq == MAP_FAILED)
+ if (wq == MAP_FAILED){
+ close(fd);
perror("mmap");
-
+ }
return wq;
}
--
2.43.0
next prev parent reply other threads:[~2025-04-07 10:45 UTC|newest]
Thread overview: 13+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-03-24 12:47 [PATCH] selftests/x86/lam: fix memory leak and resource leak in lam.c Malaya Kumar Rout
2025-03-24 12:51 ` Peter Zijlstra
2025-03-25 9:29 ` Ingo Molnar
2025-03-25 9:56 ` malaya kumar rout
2025-03-25 13:25 ` Malaya Kumar Rout
2025-04-07 10:44 ` Malaya Kumar Rout [this message]
2025-04-07 18:20 ` [PATCH v2] selftests/x86/lam: fix resource leak in do_uring() and allocate_dsa_pasid() Ingo Molnar
2025-04-07 19:34 ` [PATCH v3] " Malaya Kumar Rout
2025-04-08 8:09 ` Ingo Molnar
2025-04-08 18:52 ` RE:[PATCH RESEND x86-next v4] " Malaya Kumar Rout
2025-04-08 20:12 ` [PATCH " Ingo Molnar
2025-04-09 13:53 ` [PATCH " Malaya Kumar Rout
2025-04-09 19:41 ` [tip: x86/mm] selftests/x86/lam: Fix clean up fds " tip-bot2 for Malaya Kumar Rout
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=20250407104445.442876-1-malayarout91@gmail.com \
--to=malayarout91@gmail.com \
--cc=bp@alien8.de \
--cc=dave.hansen@linux.intel.com \
--cc=hpa@zytor.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-kselftest@vger.kernel.org \
--cc=mingo@kernel.org \
--cc=mingo@redhat.com \
--cc=shuah@kernel.org \
--cc=tglx@linutronix.de \
--cc=x86@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