From 82830f2900110bf855014bf2ca3176db2c50c539 Mon Sep 17 00:00:00 2001 From: Sebastien Vincent Date: Fri, 14 Dec 2018 14:17:53 +0100 Subject: [PATCH] [FSCP] Disables buffer recycling mechanism as it may introduce an issue of circular references. More specifically in current way of recycling, we use some lambda expressions that at one time capture the SharedBuffer variable. The lambda is stored as the deleter of the shared_ptr holding the SharedBuffer. --- libs/freelan/src/core.cpp | 5 +++++ libs/fscp/src/server.cpp | 18 ++++++++++++++++++ 2 files changed, 23 insertions(+) diff --git a/libs/freelan/src/core.cpp b/libs/freelan/src/core.cpp index 1912eb63..2f55cca5 100644 --- a/libs/freelan/src/core.cpp +++ b/libs/freelan/src/core.cpp @@ -2054,16 +2054,21 @@ namespace freelan return result; }(); + // disable buffer recycling from now (possible issue with SharedBuffer + // which references itself due to lambda capture) m_tap_adapter->async_read( buffer(receive_buffer), boost::bind( &core::do_handle_tap_adapter_read, this, + /* SharedBuffer(receive_buffer, [this](const SharedBuffer& buffer) { m_tap_adapter_io_service.post([this, buffer] () { m_tap_adapter_buffers.push_back(buffer); }); }), + */ + receive_buffer, boost::asio::placeholders::error, boost::asio::placeholders::bytes_transferred ) diff --git a/libs/fscp/src/server.cpp b/libs/fscp/src/server.cpp index 80bd8ed2..cd6002b7 100644 --- a/libs/fscp/src/server.cpp +++ b/libs/fscp/src/server.cpp @@ -1537,12 +1537,17 @@ namespace fscp ); } + // disable buffer recycling from now (possible issue with SharedBuffer + // which references itself due to lambda capture) async_send_to( + /* SharedBuffer(send_buffer, [this](const SharedBuffer& buffer) { m_session_strand.post([this, buffer]() { m_session_buffers.push_back(buffer); }); }), + */ + send_buffer, size, target, handler @@ -1824,12 +1829,17 @@ namespace fscp ); } + // disable buffer recycling from now (possible issue with SharedBuffer + // which references itself due to lambda capture) async_send_to( + /* SharedBuffer(send_buffer, [this](const SharedBuffer& buffer) { m_session_strand.post([this, buffer]() { m_session_buffers.push_back(buffer); }); }), + */ + send_buffer, size, target, [] (const boost::system::error_code&) {} @@ -2139,12 +2149,17 @@ namespace fscp buffer_size(p_session.current_session().local_nonce_prefix) ); + // disable buffer recycling from now (possible issue with SharedBuffer + // which references itself due to lambda capture) async_send_to( + /* SharedBuffer(send_buffer, [this](const SharedBuffer& buffer) { m_session_strand.post([this, buffer]() { m_session_buffers.push_back(buffer); }); }), + */ + send_buffer, size, target, handler @@ -2370,11 +2385,14 @@ namespace fscp do_handle_data_message( sender, type, + /* SharedBuffer(cleartext_buffer, [this] (const SharedBuffer& buffer) { m_session_strand.post([this, buffer] () { m_session_buffers.push_back(buffer); }); }), + */ + cleartext_buffer, buffer(cleartext_buffer, cleartext_len) ); }