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)
MFC after:	2 weeks
Sponsored by:	Axcient
This commit is contained in:
Alan Somers 2022-05-05 09:06:04 -06:00
parent dcfa054216
commit 4ac4b12699
6 changed files with 36 additions and 0 deletions

View File

@ -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",

View File

@ -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,

View File

@ -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);
}
/*

View File

@ -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

View File

@ -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);
}

View File

@ -217,6 +217,7 @@ TEST_F(Open, multiple_creds)
perror("open");
return(1);
}
leak(fd0);
return 0;
}
);