From: Trieu Huynh <vikingtc4@gmail.com>
ufd_version_check() opens a userfaultfd via uffd_open() but never closes
it on any path where the open succeeded: the UFFDIO_API failure path,
the missing-ioctls path, and the success path all returned without
calling close(ufd).
Convert to a goto-out pattern consistent with uffd_open() used in
util/userfaultfd.c and migration/postcopy-ram.c, ensuring the fd is
always closed before returning.
Signed-off-by: Trieu Huynh <vikingtc4@gmail.com>
---
tests/qtest/migration/migration-util.c | 10 +++++++---
1 file changed, 7 insertions(+), 3 deletions(-)
diff --git a/tests/qtest/migration/migration-util.c b/tests/qtest/migration/migration-util.c
index 2648ad7f61..db66d8b24f 100644
--- a/tests/qtest/migration/migration-util.c
+++ b/tests/qtest/migration/migration-util.c
@@ -343,6 +343,7 @@ bool ufd_version_check(bool *uffd_feature_thread_id)
{
struct uffdio_api api_struct;
uint64_t ioctl_mask;
+ bool ret = false;
int ufd = uffd_open(O_CLOEXEC);
@@ -355,7 +356,7 @@ bool ufd_version_check(bool *uffd_feature_thread_id)
api_struct.features = 0;
if (ioctl(ufd, UFFDIO_API, &api_struct)) {
g_test_message("Skipping test: UFFDIO_API failed");
- return false;
+ goto release_ufd;
}
if (uffd_feature_thread_id) {
@@ -366,10 +367,13 @@ bool ufd_version_check(bool *uffd_feature_thread_id)
1ULL << _UFFDIO_UNREGISTER);
if ((api_struct.ioctls & ioctl_mask) != ioctl_mask) {
g_test_message("Skipping test: Missing userfault feature");
- return false;
+ goto release_ufd;
}
- return true;
+ ret = true;
+release_ufd:
+ close(ufd);
+ return ret;
}
#else
bool ufd_version_check(bool *uffd_feature_thread_id)
--
2.43.0