git: 8272680eecb5 - stable/13 - fusefs: annotate more file descriptor leaks in the tests
- Go to: [ bottom of page ] [ top of archives ] [ this month ]
Date: Mon, 23 May 2022 19:11:50 UTC
The branch stable/13 has been updated by asomers: URL: https://cgit.FreeBSD.org/src/commit/?id=8272680eecb59be218f64e3d38da6b4b6c07ae95 commit 8272680eecb59be218f64e3d38da6b4b6c07ae95 Author: Alan Somers <asomers@FreeBSD.org> AuthorDate: 2022-05-05 15:06:04 +0000 Commit: Alan Somers <asomers@FreeBSD.org> CommitDate: 2022-05-23 19:11:19 +0000 fusefs: annotate more file descriptor leaks in the tests The fusefs tests intentionally leak file descriptors. Annotate all of the leakages in order to hopefully pacify Coverity. Reported by: Coverity (20 different CIDs) Sponsored by: Axcient (cherry picked from commit 4ac4b12699fd423165a0ac0d05630a1fae022bbb) --- tests/sys/fs/fusefs/allow_other.cc | 4 ++++ tests/sys/fs/fusefs/bmap.cc | 4 ++++ tests/sys/fs/fusefs/copy_file_range.cc | 5 +++++ tests/sys/fs/fusefs/last_local_modify.cc | 2 ++ tests/sys/fs/fusefs/lseek.cc | 20 ++++++++++++++++++++ tests/sys/fs/fusefs/open.cc | 1 + 6 files changed, 36 insertions(+) diff --git a/tests/sys/fs/fusefs/allow_other.cc b/tests/sys/fs/fusefs/allow_other.cc index 0ddcc920f4af..30488dbbb0eb 100644 --- a/tests/sys/fs/fusefs/allow_other.cc +++ b/tests/sys/fs/fusefs/allow_other.cc @@ -94,6 +94,8 @@ TEST_F(AllowOther, allowed) perror("open"); return(1); } + + leak(fd); return 0; } ); @@ -201,6 +203,7 @@ TEST_F(NoAllowOther, disallowed) fd = open(FULLPATH, O_RDONLY); if (fd >= 0) { fprintf(stderr, "open should've failed\n"); + leak(fd); return(1); } else if (errno != EPERM) { fprintf(stderr, "Unexpected error: %s\n", @@ -245,6 +248,7 @@ TEST_F(NoAllowOther, disallowed_beneath_root) fd = openat(dfd, RELPATH2, O_RDONLY); if (fd >= 0) { fprintf(stderr, "openat should've failed\n"); + leak(fd); return(1); } else if (errno != EPERM) { fprintf(stderr, "Unexpected error: %s\n", diff --git a/tests/sys/fs/fusefs/bmap.cc b/tests/sys/fs/fusefs/bmap.cc index c635f4d7e46f..91c9c4f85b64 100644 --- a/tests/sys/fs/fusefs/bmap.cc +++ b/tests/sys/fs/fusefs/bmap.cc @@ -109,6 +109,8 @@ TEST_F(Bmap, bmap) EXPECT_EQ(arg.bn, pbn); EXPECT_EQ(arg.runp, m_maxphys / m_maxbcachebuf - 1); EXPECT_EQ(arg.runb, m_maxphys / m_maxbcachebuf - 1); + + leak(fd); } /* @@ -246,6 +248,8 @@ TEST_P(BmapEof, eof) fd = open(FULLPATH, O_RDWR); ASSERT_LE(0, fd) << strerror(errno); read(fd, buf, filesize); + + leak(fd); } INSTANTIATE_TEST_CASE_P(BE, BmapEof, diff --git a/tests/sys/fs/fusefs/copy_file_range.cc b/tests/sys/fs/fusefs/copy_file_range.cc index 974dc474f77b..7e1189648de3 100644 --- a/tests/sys/fs/fusefs/copy_file_range.cc +++ b/tests/sys/fs/fusefs/copy_file_range.cc @@ -437,6 +437,8 @@ TEST_F(CopyFileRange, same_file) fd = open(FULLPATH, O_RDWR); ASSERT_EQ(len, copy_file_range(fd, &off_in, fd, &off_out, len, 0)); + + leak(fd); } /* @@ -597,6 +599,9 @@ TEST_F(CopyFileRange_7_27, fallback) fd2 = open(FULLPATH2, O_WRONLY); ASSERT_GE(fd2, 0); ASSERT_EQ(len, copy_file_range(fd1, &start1, fd2, &start2, len, 0)); + + leak(fd1); + leak(fd2); } /* diff --git a/tests/sys/fs/fusefs/last_local_modify.cc b/tests/sys/fs/fusefs/last_local_modify.cc index 9826296c80c3..ce2e155af49a 100644 --- a/tests/sys/fs/fusefs/last_local_modify.cc +++ b/tests/sys/fs/fusefs/last_local_modify.cc @@ -119,6 +119,7 @@ static void* allocate_th(void* arg) { return (void*)(intptr_t)errno; r = posix_fallocate(fd, 0, 15); + LastLocalModify::leak(fd); if (r >= 0) return 0; else @@ -160,6 +161,7 @@ static void* setattr_th(void* arg) { return (void*)(intptr_t)errno; r = ftruncate(fd, 15); + LastLocalModify::leak(fd); if (r >= 0) return 0; else diff --git a/tests/sys/fs/fusefs/lseek.cc b/tests/sys/fs/fusefs/lseek.cc index 089b0f86a7f6..5ba176f0776d 100644 --- a/tests/sys/fs/fusefs/lseek.cc +++ b/tests/sys/fs/fusefs/lseek.cc @@ -77,6 +77,8 @@ TEST_F(LseekPathconf, already_enosys) EXPECT_EQ(offset_in, lseek(fd, offset_in, SEEK_DATA)); EXPECT_EQ(-1, fpathconf(fd, _PC_MIN_HOLE_SIZE)); EXPECT_EQ(EINVAL, errno); + + leak(fd); } /* @@ -108,6 +110,8 @@ TEST_F(LseekPathconf, already_seeked) EXPECT_EQ(offset, lseek(fd, offset, SEEK_DATA)); EXPECT_EQ(1, fpathconf(fd, _PC_MIN_HOLE_SIZE)); + + leak(fd); } /* @@ -135,6 +139,8 @@ TEST_F(LseekPathconf, enosys_now) EXPECT_EQ(-1, fpathconf(fd, _PC_MIN_HOLE_SIZE)); EXPECT_EQ(EINVAL, errno); + + leak(fd); } /* @@ -169,6 +175,8 @@ TEST_F(LseekPathconf, seek_now) EXPECT_EQ(1, fpathconf(fd, _PC_MIN_HOLE_SIZE)); /* And check that the file pointer hasn't changed */ EXPECT_EQ(offset_initial, lseek(fd, 0, SEEK_CUR)); + + leak(fd); } /* @@ -194,6 +202,8 @@ TEST_F(LseekPathconf_7_23, already_enosys) fd = open(FULLPATH, O_RDONLY); EXPECT_EQ(-1, fpathconf(fd, _PC_MIN_HOLE_SIZE)); EXPECT_EQ(EINVAL, errno); + + leak(fd); } TEST_F(LseekSeekData, ok) @@ -224,6 +234,8 @@ TEST_F(LseekSeekData, ok) fd = open(FULLPATH, O_RDONLY); EXPECT_EQ(offset_out, lseek(fd, offset_in, SEEK_DATA)); EXPECT_EQ(offset_out, lseek(fd, 0, SEEK_CUR)); + + leak(fd); } /* @@ -262,6 +274,8 @@ TEST_F(LseekSeekData, enosys) EXPECT_EQ(ENXIO, errno); EXPECT_EQ(-1, lseek(fd, fsize, SEEK_HOLE)); EXPECT_EQ(ENXIO, errno); + + leak(fd); } TEST_F(LseekSeekHole, ok) @@ -292,6 +306,8 @@ TEST_F(LseekSeekHole, ok) fd = open(FULLPATH, O_RDONLY); EXPECT_EQ(offset_out, lseek(fd, offset_in, SEEK_HOLE)); EXPECT_EQ(offset_out, lseek(fd, 0, SEEK_CUR)); + + leak(fd); } /* @@ -330,6 +346,8 @@ TEST_F(LseekSeekHole, enosys) EXPECT_EQ(ENXIO, errno); EXPECT_EQ(-1, lseek(fd, fsize, SEEK_HOLE)); EXPECT_EQ(ENXIO, errno); + + leak(fd); } /* lseek should return ENXIO when offset points to EOF */ @@ -357,4 +375,6 @@ TEST_F(LseekSeekHole, enxio) fd = open(FULLPATH, O_RDONLY); EXPECT_EQ(-1, lseek(fd, offset_in, SEEK_HOLE)); EXPECT_EQ(ENXIO, errno); + + leak(fd); } diff --git a/tests/sys/fs/fusefs/open.cc b/tests/sys/fs/fusefs/open.cc index 7ac177a65d14..c1314fc0d02a 100644 --- a/tests/sys/fs/fusefs/open.cc +++ b/tests/sys/fs/fusefs/open.cc @@ -217,6 +217,7 @@ TEST_F(Open, multiple_creds) perror("open"); return(1); } + leak(fd0); return 0; } );