diff options
author | cheatfate <ka@hardcore.kiev.ua> | 2016-08-30 23:15:08 +0300 |
---|---|---|
committer | cheatfate <ka@hardcore.kiev.ua> | 2016-08-30 23:15:08 +0300 |
commit | c5ffdd03897225ebcb8bef23bdb64f212c45e8e8 (patch) | |
tree | 923db633e3610b4d267d4297f05a67cf09e01a3e /lib/upcoming | |
parent | 283f8e9c8cb1ca1efc2d8c7c8a85a9cc86f579d0 (diff) | |
download | Nim-c5ffdd03897225ebcb8bef23bdb64f212c45e8e8.tar.gz |
Protect data argument for GC.
Diffstat (limited to 'lib/upcoming')
-rw-r--r-- | lib/upcoming/asyncdispatch.nim | 7 |
1 files changed, 6 insertions, 1 deletions
diff --git a/lib/upcoming/asyncdispatch.nim b/lib/upcoming/asyncdispatch.nim index 19c9815d2..4a079e895 100644 --- a/lib/upcoming/asyncdispatch.nim +++ b/lib/upcoming/asyncdispatch.nim @@ -796,14 +796,17 @@ when defined(windows) or defined(nimdoc): var retFuture = newFuture[void]("send") var dataBuf: TWSABuf - dataBuf.buf = data # since this is not used in a callback, this is fine + dataBuf.buf = data dataBuf.len = data.len.ULONG + GC_ref(data) # we need to protect data until send operation is completed + # or failed. var bytesReceived, lowFlags: Dword var ol = PCustomOverlapped() GC_ref(ol) ol.data = CompletionData(fd: socket, cb: proc (fd: AsyncFD, bytesCount: Dword, errcode: OSErrorCode) = + GC_unref(data) # if operation completed `data` must be released. if not retFuture.finished: if errcode == OSErrorCode(-1): retFuture.complete() @@ -820,6 +823,8 @@ when defined(windows) or defined(nimdoc): let err = osLastError() if err.int32 != ERROR_IO_PENDING: GC_unref(ol) + GC_unref(data) # if operation failed `data` must be released, because + # completion routine will not be called. if flags.isDisconnectionError(err): retFuture.complete() else: |