teknoraver / rpms / systemd

Forked from rpms/systemd a month ago
Clone

Blame SOURCES/0120-test-fix-file-descriptor-leak-in-test-tmpfiles.c.patch

594167
From 936e8cd5aff044832c98e5a6a97c9f057f44b476 Mon Sep 17 00:00:00 2001
594167
From: Yu Watanabe <watanabe.yu+github@gmail.com>
594167
Date: Tue, 22 Feb 2022 21:44:58 +0900
594167
Subject: [PATCH] test: fix file descriptor leak in test-tmpfiles.c
594167
594167
Also fixes a typo in assertion.
594167
594167
Fixes an issure reported in #22576.
594167
594167
(cherry picked from commit 1da5325d19dee654326e5fa2f61262e5e0a40fff)
594167
Related: #2087652
594167
---
594167
 src/test/test-tmpfiles.c | 3 ++-
594167
 1 file changed, 2 insertions(+), 1 deletion(-)
594167
594167
diff --git a/src/test/test-tmpfiles.c b/src/test/test-tmpfiles.c
594167
index 99243eb77a..f26701767f 100644
594167
--- a/src/test/test-tmpfiles.c
594167
+++ b/src/test/test-tmpfiles.c
594167
@@ -35,7 +35,7 @@ TEST(tmpfiles) {
594167
         assert_se(endswith(ans, " (deleted)"));
594167
 
594167
         fd2 = mkostemp_safe(pattern);
594167
-        assert_se(fd >= 0);
594167
+        assert_se(fd2 >= 0);
594167
         assert_se(unlink(pattern) == 0);
594167
 
594167
         assert_se(asprintf(&cmd2, "ls -l /proc/"PID_FMT"/fd/%d", getpid_cached(), fd2) > 0);
594167
@@ -47,6 +47,7 @@ TEST(tmpfiles) {
594167
         pattern = strjoina(p, "/tmpfiles-test");
594167
         assert_se(tempfn_random(pattern, NULL, &d) >= 0);
594167
 
594167
+        fd = safe_close(fd);
594167
         fd = open_tmpfile_linkable(d, O_RDWR|O_CLOEXEC, &tmp);
594167
         assert_se(fd >= 0);
594167
         assert_se(write(fd, "foobar\n", 7) == 7);