From 3c917d6fa3e9676d34c99875f5fd905de659d4e4 Mon Sep 17 00:00:00 2001 From: Enji Cooper Date: Wed, 4 Jan 2017 03:35:23 +0000 Subject: [PATCH] unlink_fifo: don't leak the file descriptors opened with mkfifo and open MFC fater: 3 days Reported by: Coverity CID: 978316, 978317 --- contrib/netbsd-tests/lib/libc/sys/t_unlink.c | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/contrib/netbsd-tests/lib/libc/sys/t_unlink.c b/contrib/netbsd-tests/lib/libc/sys/t_unlink.c index 8d9466881cba..e72974c7d133 100644 --- a/contrib/netbsd-tests/lib/libc/sys/t_unlink.c +++ b/contrib/netbsd-tests/lib/libc/sys/t_unlink.c @@ -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)