unlink_fifo: don't leak the file descriptors opened with mkfifo and open

MFC fater:	3 days
Reported by:	Coverity
CID:		978316, 978317
This commit is contained in:
Enji Cooper 2017-01-04 03:35:23 +00:00
parent 6a64e31600
commit 3c917d6fa3
Notes: svn2git 2020-12-20 02:59:44 +00:00
svn path=/head/; revision=311236

View File

@ -63,7 +63,12 @@ ATF_TC_BODY(unlink_basic, tc)
ATF_REQUIRE(unlink(path) == 0);
errno = 0;
#ifdef __FreeBSD__
ATF_REQUIRE_ERRNO(ENOENT, (fd = open(path, O_RDONLY)) == -1);
(void)close(fd);
#else
ATF_REQUIRE_ERRNO(ENOENT, open(path, O_RDONLY) == -1);
#endif
}
}
@ -111,12 +116,24 @@ ATF_TC_HEAD(unlink_fifo, tc)
ATF_TC_BODY(unlink_fifo, tc)
{
#ifdef __FreeBSD__
int fd;
ATF_REQUIRE_MSG((fd = mkfifo(path, 0666)) == 0,
"mkfifo failed: %s", strerror(errno));
(void)close(fd);
#else
ATF_REQUIRE(mkfifo(path, 0666) == 0);
#endif
ATF_REQUIRE(unlink(path) == 0);
errno = 0;
#ifdef __FreeBSD__
ATF_REQUIRE_ERRNO(ENOENT, (fd = open(path, O_RDONLY)) == -1);
(void)close(fd);
#else
ATF_REQUIRE_ERRNO(ENOENT, open(path, O_RDONLY) == -1);
#endif
}
ATF_TC_CLEANUP(unlink_fifo, tc)