From 6473aeebe61b6d553df1d6f6e88b90200a740130 Mon Sep 17 00:00:00 2001 From: Lev Stipakov Date: Fri, 29 May 2020 12:17:36 +0300 Subject: [PATCH] ringbuffer.hpp: fix SEH exception in destructor under debugger When running under debugger, CloseHandle() throws SEH exception when handle is already closed. In this case handle was attempted to close twice - first by destructor of WinEvent and then by destructor of AsioEvent. Fix by assigning duplicated handle to AsioEvent. Reported-By: Anthony Wharton Signed-off-by: Lev Stipakov --- openvpn/tun/win/ringbuffer.hpp | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/openvpn/tun/win/ringbuffer.hpp b/openvpn/tun/win/ringbuffer.hpp index ab6cde7f..9bb7e60c 100644 --- a/openvpn/tun/win/ringbuffer.hpp +++ b/openvpn/tun/win/ringbuffer.hpp @@ -82,7 +82,11 @@ namespace openvpn send_ring_ = (TUN_RING*)MapViewOfFile(send_ring_hmem(), FILE_MAP_ALL_ACCESS, 0, 0, sizeof(TUN_RING)); receive_ring_ = (TUN_RING*)MapViewOfFile(receive_ring_hmem(), FILE_MAP_ALL_ACCESS, 0, 0, sizeof(TUN_RING)); - send_tail_moved_asio_event_.assign(send_ring_tail_moved_()); + + HANDLE handle; + DuplicateHandle(GetCurrentProcess(), send_ring_tail_moved_(), + GetCurrentProcess(), &handle, 0, FALSE, DUPLICATE_SAME_ACCESS); + send_tail_moved_asio_event_.assign(handle); } RingBuffer(openvpn_io::io_context& io_context,