[vlc-commits] posix: assert that we do not close a corrupt FD
Rémi Denis-Courmont
git at videolan.org
Thu Feb 23 20:08:28 CET 2017
vlc | branch: master | Rémi Denis-Courmont <remi at remlab.net> | Wed Feb 22 23:32:33 2017 +0200| [7dba562c2600c8ddf93ab35dbf45b161599e3f9a] | committer: Rémi Denis-Courmont
posix: assert that we do not close a corrupt FD
This helps detect double-close or other bugs.
> http://git.videolan.org/gitweb.cgi/vlc.git/?a=commit;h=7dba562c2600c8ddf93ab35dbf45b161599e3f9a
---
src/posix/filesystem.c | 8 +++++---
1 file changed, 5 insertions(+), 3 deletions(-)
diff --git a/src/posix/filesystem.c b/src/posix/filesystem.c
index af830ff..728286d 100644
--- a/src/posix/filesystem.c
+++ b/src/posix/filesystem.c
@@ -134,17 +134,19 @@ int vlc_memfd (void)
int vlc_close (int fd)
{
+ int ret;
#ifdef POSIX_CLOSE_RESTART
- return posix_close (fd, 0);
+ ret = posix_close(fd, 0);
#else
- int ret = close (fd);
+ ret = close(fd);
/* POSIX.2008 (and earlier) does not specify if the file descriptor is
* closed on failure. Assume it is as on Linux and most other common OSes.
* Also emulate the correct error code as per newer POSIX versions. */
if (unlikely(ret != 0) && unlikely(errno == EINTR))
errno = EINPROGRESS;
- return ret;
#endif
+ assert(ret == 0 || errno != EBADF); /* something is corrupt? */
+ return ret;
}
int vlc_mkdir (const char *dirname, mode_t mode)
More information about the vlc-commits
mailing list