Merge pull request #43 from jmjatlanta/Issue_socket
Memory leak on socket destruction
This commit is contained in:
commit
ccc213b72d
5 changed files with 26 additions and 12 deletions
|
|
@ -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
|
||||
|
|
|
|||
16
src/asio.cpp
16
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;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -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() {
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
17
tests/io/tcp_test.cpp
Normal file
17
tests/io/tcp_test.cpp
Normal file
|
|
@ -0,0 +1,17 @@
|
|||
#include <boost/test/unit_test.hpp>
|
||||
|
||||
#include <fc/network/tcp_socket.hpp>
|
||||
|
||||
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()
|
||||
Loading…
Reference in a new issue