ryantimwilson / rpms / systemd

Forked from rpms/systemd a month ago
Clone
594167
From 3ca37c58cb3ff022e029b28539fd2e3b208802fd Mon Sep 17 00:00:00 2001
594167
From: Yu Watanabe <watanabe.yu+github@gmail.com>
594167
Date: Tue, 22 Feb 2022 21:42:22 +0900
594167
Subject: [PATCH] test: fix file descriptor leak in test-fs-util
594167
594167
Fixes an issue reported in #22576.
594167
594167
(cherry picked from commit 19962747ca86a25e7102c536380bb2e9d7cfee9a)
594167
Related: #2087652
594167
---
594167
 src/test/test-fs-util.c | 5 ++++-
594167
 1 file changed, 4 insertions(+), 1 deletion(-)
594167
594167
diff --git a/src/test/test-fs-util.c b/src/test/test-fs-util.c
594167
index 602ce75f98..f53a3ebf59 100644
594167
--- a/src/test/test-fs-util.c
594167
+++ b/src/test/test-fs-util.c
594167
@@ -29,10 +29,11 @@ static const char *arg_test_dir = NULL;
594167
 
594167
 TEST(chase_symlinks) {
594167
         _cleanup_free_ char *result = NULL;
594167
+        _cleanup_close_ int pfd = -1;
594167
         char *temp;
594167
         const char *top, *p, *pslash, *q, *qslash;
594167
         struct stat st;
594167
-        int r, pfd;
594167
+        int r;
594167
 
594167
         temp = strjoina(arg_test_dir ?: "/tmp", "/test-chase.XXXXXX");
594167
         assert_se(mkdtemp(temp));
594167
@@ -318,6 +319,7 @@ TEST(chase_symlinks) {
594167
         assert_se(fstat(pfd, &st) >= 0);
594167
         assert_se(S_ISLNK(st.st_mode));
594167
         result = mfree(result);
594167
+        pfd = safe_close(pfd);
594167
 
594167
         /* s1 -> s2 -> nonexistent */
594167
         q = strjoina(temp, "/s1");
594167
@@ -331,6 +333,7 @@ TEST(chase_symlinks) {
594167
         assert_se(fstat(pfd, &st) >= 0);
594167
         assert_se(S_ISLNK(st.st_mode));
594167
         result = mfree(result);
594167
+        pfd = safe_close(pfd);
594167
 
594167
         /* Test CHASE_STEP */
594167