Author: ngie
Date: Wed Jan  4 03:35:23 2017
New Revision: 311236
URL: https://svnweb.freebsd.org/changeset/base/311236

Log:
  unlink_fifo: don't leak the file descriptors opened with mkfifo and open
  
  MFC fater:    3 days
  Reported by:  Coverity
  CID:          978316, 978317

Modified:
  head/contrib/netbsd-tests/lib/libc/sys/t_unlink.c

Modified: head/contrib/netbsd-tests/lib/libc/sys/t_unlink.c
==============================================================================
--- head/contrib/netbsd-tests/lib/libc/sys/t_unlink.c   Wed Jan  4 02:52:39 
2017        (r311235)
+++ head/contrib/netbsd-tests/lib/libc/sys/t_unlink.c   Wed Jan  4 03:35:23 
2017        (r311236)
@@ -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)
_______________________________________________
svn-src-all@freebsd.org mailing list
https://lists.freebsd.org/mailman/listinfo/svn-src-all
To unsubscribe, send any mail to "svn-src-all-unsubscr...@freebsd.org"

Reply via email to