summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorYu Watanabe <watanabe.yu+github@gmail.com>2022-02-22 21:42:22 +0900
committerLuca Boccassi <luca.boccassi@gmail.com>2022-03-05 21:03:32 +0000
commitcfe1cd0a066b29e5508b4a2c388fd919fd5e0c9f (patch)
treefc070681a06b1a3686e3258efc889a25e870d780
parente37912e4bc2e3b15785af888b0f472b785132568 (diff)
downloadsystemd-cfe1cd0a066b29e5508b4a2c388fd919fd5e0c9f.tar.gz
test: fix file descriptor leak in test-fs-util
Fixes an issue reported in #22576. (cherry picked from commit 19962747ca86a25e7102c536380bb2e9d7cfee9a)
-rw-r--r--src/test/test-fs-util.c5
1 files changed, 4 insertions, 1 deletions
diff --git a/src/test/test-fs-util.c b/src/test/test-fs-util.c
index 0e0d91d04e..d527ad3d7e 100644
--- a/src/test/test-fs-util.c
+++ b/src/test/test-fs-util.c
@@ -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 */