aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorWladimir J. van der Laan <laanwj@gmail.com>2014-05-07 09:24:44 +0200
committerWladimir J. van der Laan <laanwj@gmail.com>2014-05-12 17:56:55 +0200
commit203a0cfa7cb0d7e9f43ad8488ecaf7ffbf40ddfc (patch)
tree7bb7f6d5284e36246def4b92e5ec6807605ddb6f
parent1ed6d499b6bf02a399fb32059caccdea847335b0 (diff)
downloadbitcoin-203a0cfa7cb0d7e9f43ad8488ecaf7ffbf40ddfc.tar.xz
rpc: Make sure conn object is always cleaned up
Make sure conn object always gets cleaned up by using a `boost::shared_ptr`. This makes valgrind happy - before this commit, one connection object always leaked at shutdown, as well as can avoid other leaks, when for example an exception happens. Also add an explicit Close() to the !ClientAllowed path to make it similar to the normal path (I'm not sure whether it is needed, but it can't hurt). Rebased-By: Wladimir J. van der Laan Rebased-From: 1a44522
-rw-r--r--src/rpcserver.cpp16
1 files changed, 6 insertions, 10 deletions
diff --git a/src/rpcserver.cpp b/src/rpcserver.cpp
index fb7a28db77..41a1d6d96a 100644
--- a/src/rpcserver.cpp
+++ b/src/rpcserver.cpp
@@ -435,7 +435,7 @@ template <typename Protocol, typename SocketAcceptorService>
static void RPCAcceptHandler(boost::shared_ptr< basic_socket_acceptor<Protocol, SocketAcceptorService> > acceptor,
ssl::context& context,
bool fUseSSL,
- AcceptedConnection* conn,
+ boost::shared_ptr< AcceptedConnection > conn,
const boost::system::error_code& error);
/**
@@ -447,7 +447,7 @@ static void RPCListen(boost::shared_ptr< basic_socket_acceptor<Protocol, SocketA
const bool fUseSSL)
{
// Accept connection
- AcceptedConnectionImpl<Protocol>* conn = new AcceptedConnectionImpl<Protocol>(acceptor->get_io_service(), context, fUseSSL);
+ boost::shared_ptr< AcceptedConnectionImpl<Protocol> > conn(new AcceptedConnectionImpl<Protocol>(acceptor->get_io_service(), context, fUseSSL));
acceptor->async_accept(
conn->sslStream.lowest_layer(),
@@ -468,23 +468,20 @@ template <typename Protocol, typename SocketAcceptorService>
static void RPCAcceptHandler(boost::shared_ptr< basic_socket_acceptor<Protocol, SocketAcceptorService> > acceptor,
ssl::context& context,
const bool fUseSSL,
- AcceptedConnection* conn,
+ boost::shared_ptr< AcceptedConnection > conn,
const boost::system::error_code& error)
{
// Immediately start accepting new connections, except when we're cancelled or our socket is closed.
if (error != asio::error::operation_aborted && acceptor->is_open())
RPCListen(acceptor, context, fUseSSL);
- AcceptedConnectionImpl<ip::tcp>* tcp_conn = dynamic_cast< AcceptedConnectionImpl<ip::tcp>* >(conn);
+ AcceptedConnectionImpl<ip::tcp>* tcp_conn = dynamic_cast< AcceptedConnectionImpl<ip::tcp>* >(conn.get());
- // TODO: Actually handle errors
if (error)
{
- delete conn;
// TODO: Actually handle errors
LogPrintf("%s: Error: %s\n", __func__, error.message());
}
-
// Restrict callers by IP. It is important to
// do this before starting client thread, to filter out
// certain DoS and misbehaving clients.
@@ -493,12 +490,11 @@ static void RPCAcceptHandler(boost::shared_ptr< basic_socket_acceptor<Protocol,
// Only send a 403 if we're not using SSL to prevent a DoS during the SSL handshake.
if (!fUseSSL)
conn->stream() << HTTPReply(HTTP_FORBIDDEN, "", false) << std::flush;
- delete conn;
+ conn->close();
}
else {
- ServiceConnection(conn);
+ ServiceConnection(conn.get());
conn->close();
- delete conn;
}
}