]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
test: fix file descriptor leak in test-fs-util
authorYu Watanabe <watanabe.yu+github@gmail.com>
Tue, 22 Feb 2022 12:42:22 +0000 (21:42 +0900)
committerYu Watanabe <watanabe.yu+github@gmail.com>
Tue, 22 Feb 2022 15:58:13 +0000 (00:58 +0900)
Fixes an issue reported in #22576.

src/test/test-fs-util.c

index 602ce75f9804e7426f787a6077bfeda55291fc07..f53a3ebf59c3a1ac08ea5223fd9cc3aa43c3d2a3 100644 (file)
@@ -29,10 +29,11 @@ static const char *arg_test_dir = NULL;
 
 TEST(chase_symlinks) {
         _cleanup_free_ char *result = NULL;
+        _cleanup_close_ int pfd = -1;
         char *temp;
         const char *top, *p, *pslash, *q, *qslash;
         struct stat st;
-        int r, pfd;
+        int r;
 
         temp = strjoina(arg_test_dir ?: "/tmp", "/test-chase.XXXXXX");
         assert_se(mkdtemp(temp));
@@ -318,6 +319,7 @@ TEST(chase_symlinks) {
         assert_se(fstat(pfd, &st) >= 0);
         assert_se(S_ISLNK(st.st_mode));
         result = mfree(result);
+        pfd = safe_close(pfd);
 
         /* s1 -> s2 -> nonexistent */
         q = strjoina(temp, "/s1");
@@ -331,6 +333,7 @@ TEST(chase_symlinks) {
         assert_se(fstat(pfd, &st) >= 0);
         assert_se(S_ISLNK(st.st_mode));
         result = mfree(result);
+        pfd = safe_close(pfd);
 
         /* Test CHASE_STEP */