]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
test: fix file descriptor leak in test-tmpfiles.c
authorYu Watanabe <watanabe.yu+github@gmail.com>
Tue, 22 Feb 2022 12:44:58 +0000 (21:44 +0900)
committerYu Watanabe <watanabe.yu+github@gmail.com>
Tue, 22 Feb 2022 15:58:16 +0000 (00:58 +0900)
Also fixes a typo in assertion.

Fixes an issure reported in #22576.

src/test/test-tmpfiles.c

index 99243eb77aef7cb226bb655e595c63ab24b387d5..f26701767f3bf951e6ba1232ae1c883bebc46422 100644 (file)
@@ -35,7 +35,7 @@ TEST(tmpfiles) {
         assert_se(endswith(ans, " (deleted)"));
 
         fd2 = mkostemp_safe(pattern);
-        assert_se(fd >= 0);
+        assert_se(fd2 >= 0);
         assert_se(unlink(pattern) == 0);
 
         assert_se(asprintf(&cmd2, "ls -l /proc/"PID_FMT"/fd/%d", getpid_cached(), fd2) > 0);
@@ -47,6 +47,7 @@ TEST(tmpfiles) {
         pattern = strjoina(p, "/tmpfiles-test");
         assert_se(tempfn_random(pattern, NULL, &d) >= 0);
 
+        fd = safe_close(fd);
         fd = open_tmpfile_linkable(d, O_RDWR|O_CLOEXEC, &tmp);
         assert_se(fd >= 0);
         assert_se(write(fd, "foobar\n", 7) == 7);