Skip site navigation (1)Skip section navigation (2)
Date:      Wed, 4 Jan 2017 03:35:23 +0000 (UTC)
From:      Ngie Cooper <ngie@FreeBSD.org>
To:        src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org
Subject:   svn commit: r311236 - head/contrib/netbsd-tests/lib/libc/sys
Message-ID:  <201701040335.v043ZNHh059796@repo.freebsd.org>

next in thread | raw e-mail | index | archive | help
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)



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201701040335.v043ZNHh059796>