summaryrefslogtreecommitdiffstats
path: root/otherlibs/win32unix/close.c
diff options
context:
space:
mode:
authorDamien Doligez <damien.doligez-inria.fr>2011-07-20 09:17:07 +0000
committerDamien Doligez <damien.doligez-inria.fr>2011-07-20 09:17:07 +0000
commitc91db736b18c7ed0ec81596b76874f5423d5d331 (patch)
treea967edfcd254aa6844c44e81ea33596a82b7bf87 /otherlibs/win32unix/close.c
parent46d5420ca9c695738f7a0baa527d3591d95f067a (diff)
merge changes from 3.12.0 to 3.12.1
git-svn-id: http://caml.inria.fr/svn/ocaml/trunk@11123 f963ae5c-01c2-4b8c-9fe0-0dff7051ff02
Diffstat (limited to 'otherlibs/win32unix/close.c')
-rw-r--r--otherlibs/win32unix/close.c17
1 files changed, 14 insertions, 3 deletions
diff --git a/otherlibs/win32unix/close.c b/otherlibs/win32unix/close.c
index 48cd60e7a..21254ef1e 100644
--- a/otherlibs/win32unix/close.c
+++ b/otherlibs/win32unix/close.c
@@ -15,6 +15,9 @@
#include <mlvalues.h>
#include "unixsupport.h"
+#include <io.h>
+
+extern int _close(int);
CAMLprim value unix_close(value fd)
{
@@ -24,9 +27,17 @@ CAMLprim value unix_close(value fd)
uerror("close", Nothing);
}
} else {
- if (! CloseHandle(Handle_val(fd))) {
- win32_maperr(GetLastError());
- uerror("close", Nothing);
+ /* If we have an fd then closing it also closes
+ * the underlying handle. Also, closing only
+ * the handle and not the fd leads to fd leaks. */
+ if (CRT_fd_val(fd) != NO_CRT_FD) {
+ if (_close(CRT_fd_val(fd)) != 0)
+ uerror("close", Nothing);
+ } else {
+ if (! CloseHandle(Handle_val(fd))) {
+ win32_maperr(GetLastError());
+ uerror("close", Nothing);
+ }
}
}
return Val_unit;