summaryrefslogtreecommitdiff
path: root/otherlibs/win32unix/channels.c
diff options
context:
space:
mode:
authorXavier Leroy <xavier.leroy@inria.fr>2017-10-09 15:22:02 +0200
committerXavier Leroy <xavier.leroy@inria.fr>2017-10-09 15:22:02 +0200
commit4fb49e0ed2b25f251630ecff065d1ae32c06273f (patch)
tree1f26d2dce3acfa249a257841d083ccd3c96db21a /otherlibs/win32unix/channels.c
parent8eef73ea8d0a4994cb1c7210b83ba58e00d80144 (diff)
downloadocaml-MPR7609-continued.tar.gz
MPR#7609: use-after-free with ocamldebug and Pervasives.flush_all, continuedMPR7609-continued
This is a follow-up to commit 6d9ce26 and to GPR #1361. I forgot that the win_{in,out}channel_of_filedescr functions from the Win32 implementation of the Unix library call caml_open_descriptor_{in,out} directly, without going through caml_ml_open_descriptor_{in,out} like the Unix implementation of the Unix library does. As a consequence the CHANNEL_FLAG_MANAGED_BY_GC flag is not set by the Win32 implementation. This commit fixes the Win32 implementation and brings it in sync with the Unix implementation by setting the CHANNEL_FLAG_MANAGED_BY_GC flag.
Diffstat (limited to 'otherlibs/win32unix/channels.c')
-rw-r--r--otherlibs/win32unix/channels.c4
1 files changed, 4 insertions, 0 deletions
diff --git a/otherlibs/win32unix/channels.c b/otherlibs/win32unix/channels.c
index 0347bd38a8..2749a766bd 100644
--- a/otherlibs/win32unix/channels.c
+++ b/otherlibs/win32unix/channels.c
@@ -50,6 +50,8 @@ CAMLprim value win_inchannel_of_filedescr(value handle)
fflush(stdin);
#endif
chan = caml_open_descriptor_in(win_CRT_fd_of_filedescr(handle));
+ chan->flags |= CHANNEL_FLAG_MANAGED_BY_GC;
+ /* as in caml_ml_open_descriptor_in() */
if (Descr_kind_val(handle) == KIND_SOCKET)
chan->flags |= CHANNEL_FLAG_FROM_SOCKET;
vchan = caml_alloc_channel(chan);
@@ -64,6 +66,8 @@ CAMLprim value win_outchannel_of_filedescr(value handle)
struct channel * chan;
chan = caml_open_descriptor_out(win_CRT_fd_of_filedescr(handle));
+ chan->flags |= CHANNEL_FLAG_MANAGED_BY_GC;
+ /* as in caml_ml_open_descriptor_out() */
if (Descr_kind_val(handle) == KIND_SOCKET)
chan->flags |= CHANNEL_FLAG_FROM_SOCKET;
vchan = caml_alloc_channel(chan);