diff --git a/include/fc/asio.hpp b/include/fc/asio.hpp index 9310774..6b5b4b3 100644 --- a/include/fc/asio.hpp +++ b/include/fc/asio.hpp @@ -72,7 +72,7 @@ namespace asio { * This IO service is automatically running in its own thread to service asynchronous * requests without blocking any other threads. */ - boost::asio::io_service& default_io_service(bool cleanup = false); + boost::asio::io_service& default_io_service(); /** * @brief wraps boost::asio::async_read diff --git a/src/asio.cpp b/src/asio.cpp index 1313ed7..81724ca 100644 --- a/src/asio.cpp +++ b/src/asio.cpp @@ -135,7 +135,7 @@ namespace fc { } } - void cleanup() + ~default_io_service_scope() { delete the_work; io->stop(); @@ -147,18 +147,14 @@ namespace fc { delete asio_thread; } } - - ~default_io_service_scope() - {} }; - /// If cleanup is true, do not use the return value; it is a null reference - boost::asio::io_service& default_io_service(bool cleanup) { + /*** + * @brief create an io_service + * @returns the io_service + */ + boost::asio::io_service& default_io_service() { static default_io_service_scope fc_asio_service[1]; - if (cleanup) { - for( int i = 0; i < 1; ++i ) - fc_asio_service[i].cleanup(); - } return *fc_asio_service[0].io; } diff --git a/src/network/tcp_socket.cpp b/src/network/tcp_socket.cpp index b37b40a..e521c41 100644 --- a/src/network/tcp_socket.cpp +++ b/src/network/tcp_socket.cpp @@ -90,7 +90,7 @@ namespace fc { tcp_socket::tcp_socket(){}; - tcp_socket::~tcp_socket(){}; + tcp_socket::~tcp_socket() {} void tcp_socket::flush() {} void tcp_socket::close() { diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index f2c0580..4d08855 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -51,6 +51,7 @@ add_executable( all_tests all_tests.cpp crypto/sha_tests.cpp io/json_tests.cpp io/stream_tests.cpp + io/tcp_test.cpp network/http/websocket_test.cpp thread/task_cancel.cpp thread/thread_tests.cpp diff --git a/tests/io/tcp_test.cpp b/tests/io/tcp_test.cpp new file mode 100644 index 0000000..03d46ee --- /dev/null +++ b/tests/io/tcp_test.cpp @@ -0,0 +1,17 @@ +#include + +#include + +BOOST_AUTO_TEST_SUITE(tcp_tests) + +/*** + * Running this test through valgrind will show + * a memory leak due to lack of logic in destructor. + * See https://github.com/bitshares/bitshares-fc/blob/51688042b0b9f99f03224f54fb937fe024fe5ced/src/asio.cpp#L152 + */ +BOOST_AUTO_TEST_CASE(tcpconstructor_test) +{ + fc::tcp_socket socket; +} + +BOOST_AUTO_TEST_SUITE_END()