The following commit has been merged in the master branch:
commit 96847a09687c4ab830015f41b9c198cb899b1335
Author: Romain Beauxis <to...@rastageeks.org>
Date:   Mon May 2 12:04:18 2011 -0500

    Added patch fixing fd leak with win32.

diff --git a/debian/changelog b/debian/changelog
index cd12f2f..93576be 100644
--- a/debian/changelog
+++ b/debian/changelog
@@ -4,6 +4,7 @@ mingw32-ocaml (3.12.0+debian3) unstable; urgency=low
     to force detection of cross-compiler tools
     in README.Debian
   * Fixed camlp4 META file. 
+  * Fixed fd leak in Unix.
 
  -- Romain Beauxis <to...@rastageeks.org>  Tue, 05 Apr 2011 11:58:57 -0500
 
diff --git a/debian/patches/fix_fd_leak.patch b/debian/patches/fix_fd_leak.patch
new file mode 100644
index 0000000..b369d6d
--- /dev/null
+++ b/debian/patches/fix_fd_leak.patch
@@ -0,0 +1,47 @@
+Index: build-tree/ocaml-3.12.0/otherlibs/win32unix/channels.c
+===================================================================
+--- build-tree.orig/ocaml-3.12.0/otherlibs/win32unix/channels.c        
2010-01-22 06:48:24.000000000 -0600
++++ build-tree/ocaml-3.12.0/otherlibs/win32unix/channels.c     2011-04-27 
14:38:52.000000000 -0500
+@@ -30,6 +30,7 @@
+   } else {
+     int fd = _open_osfhandle((long) Handle_val(handle), O_BINARY);
+     if (fd == -1) uerror("channel_of_descr", Nothing);
++    CRT_fd_val(handle) = fd;
+     return fd;
+   }
+ }
+Index: build-tree/ocaml-3.12.0/otherlibs/win32unix/close.c
+===================================================================
+--- build-tree.orig/ocaml-3.12.0/otherlibs/win32unix/close.c   2002-04-30 
09:00:48.000000000 -0600
++++ build-tree/ocaml-3.12.0/otherlibs/win32unix/close.c        2011-04-27 
14:39:48.000000000 -0500
+@@ -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 @@
+       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;
diff --git a/debian/patches/series b/debian/patches/series
index 70f362b..99c9e6a 100644
--- a/debian/patches/series
+++ b/debian/patches/series
@@ -14,3 +14,4 @@ mingw32-ocaml-run-ranlib-on-threads.patch
 mingw32-ocaml-force-os-type.patch
 mingw32-ocaml-win32-compat.patch
 findlib-fix-camlp4.patch
+fix_fd_leak.patch

-- 
mingw32-ocaml packaging

_______________________________________________
Pkg-ocaml-maint-commits mailing list
Pkg-ocaml-maint-commits@lists.alioth.debian.org
http://lists.alioth.debian.org/mailman/listinfo/pkg-ocaml-maint-commits

Reply via email to