mirror of
https://github.com/SChernykh/p2pool.git
synced 2025-01-03 09:19:24 +00:00
Fixed more memory leaks in TCPServer
This commit is contained in:
parent
8af9e9b27d
commit
8f1fd55e2f
2 changed files with 17 additions and 10 deletions
|
@ -127,6 +127,7 @@ private:
|
|||
static void loop(void* data);
|
||||
static void on_new_connection(uv_stream_t* server, int status);
|
||||
static void on_connection_close(uv_handle_t* handle);
|
||||
static void on_connection_error(uv_handle_t* handle);
|
||||
static void on_connect(uv_connect_t* req, int status);
|
||||
void on_new_client(uv_stream_t* server);
|
||||
void on_new_client_nolock(uv_stream_t* server, Client* client);
|
||||
|
|
|
@ -377,7 +377,7 @@ bool TCPServer<READ_BUF_SIZE, WRITE_BUF_SIZE>::connect_to_peer_nolock(Client* cl
|
|||
err = uv_tcp_nodelay(&client->m_socket, 1);
|
||||
if (err) {
|
||||
LOGERR(1, "failed to set tcp_nodelay on tcp client handle, error " << uv_err_name(err));
|
||||
m_preallocatedClients.push_back(client);
|
||||
uv_close(reinterpret_cast<uv_handle_t*>(&client->m_socket), on_connection_error);
|
||||
return false;
|
||||
}
|
||||
|
||||
|
@ -385,7 +385,7 @@ bool TCPServer<READ_BUF_SIZE, WRITE_BUF_SIZE>::connect_to_peer_nolock(Client* cl
|
|||
|
||||
if (!m_pendingConnections.insert(client->m_addr).second) {
|
||||
LOGINFO(6, "there is already a pending connection to this IP, not connecting to " << log::Gray() << static_cast<char*>(client->m_addrString));
|
||||
m_preallocatedClients.push_back(client);
|
||||
uv_close(reinterpret_cast<uv_handle_t*>(&client->m_socket), on_connection_error);
|
||||
return false;
|
||||
}
|
||||
|
||||
|
@ -397,7 +397,7 @@ bool TCPServer<READ_BUF_SIZE, WRITE_BUF_SIZE>::connect_to_peer_nolock(Client* cl
|
|||
if (err) {
|
||||
LOGERR(1, "failed to initiate tcp connection, error " << uv_err_name(err));
|
||||
m_pendingConnections.erase(client->m_addr);
|
||||
m_preallocatedClients.push_back(client);
|
||||
uv_close(reinterpret_cast<uv_handle_t*>(&client->m_socket), on_connection_error);
|
||||
return false;
|
||||
}
|
||||
else {
|
||||
|
@ -676,6 +676,16 @@ void TCPServer<READ_BUF_SIZE, WRITE_BUF_SIZE>::on_connection_close(uv_handle_t*
|
|||
}
|
||||
}
|
||||
|
||||
template<size_t READ_BUF_SIZE, size_t WRITE_BUF_SIZE>
|
||||
void TCPServer<READ_BUF_SIZE, WRITE_BUF_SIZE>::on_connection_error(uv_handle_t* handle)
|
||||
{
|
||||
Client* client = reinterpret_cast<Client*>(handle->data);
|
||||
TCPServer* server = client->m_owner;
|
||||
|
||||
MutexLock lock(server->m_clientsListLock);
|
||||
server->m_preallocatedClients.push_back(client);
|
||||
}
|
||||
|
||||
template<size_t READ_BUF_SIZE, size_t WRITE_BUF_SIZE>
|
||||
void TCPServer<READ_BUF_SIZE, WRITE_BUF_SIZE>::on_connect(uv_connect_t* req, int status)
|
||||
{
|
||||
|
@ -701,11 +711,7 @@ void TCPServer<READ_BUF_SIZE, WRITE_BUF_SIZE>::on_connect(uv_connect_t* req, int
|
|||
LOGWARN(5, "failed to connect to " << static_cast<char*>(client->m_addrString) << ", error " << uv_err_name(status));
|
||||
}
|
||||
server->on_connect_failed(client->m_isV6, client->m_addr, client->m_port);
|
||||
uv_handle_t* h = reinterpret_cast<uv_handle_t*>(&client->m_socket);
|
||||
if (!uv_is_closing(h)) {
|
||||
uv_close(h, nullptr);
|
||||
}
|
||||
server->m_preallocatedClients.push_back(client);
|
||||
uv_close(reinterpret_cast<uv_handle_t*>(&client->m_socket), on_connection_error);
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -744,14 +750,14 @@ void TCPServer<READ_BUF_SIZE, WRITE_BUF_SIZE>::on_new_client(uv_stream_t* server
|
|||
err = uv_tcp_nodelay(&client->m_socket, 1);
|
||||
if (err) {
|
||||
LOGERR(1, "failed to set tcp_nodelay on tcp client handle, error " << uv_err_name(err));
|
||||
m_preallocatedClients.push_back(client);
|
||||
uv_close(reinterpret_cast<uv_handle_t*>(&client->m_socket), on_connection_error);
|
||||
return;
|
||||
}
|
||||
|
||||
err = uv_accept(server, reinterpret_cast<uv_stream_t*>(&client->m_socket));
|
||||
if (err) {
|
||||
LOGERR(1, "failed to accept client connection, error " << uv_err_name(err));
|
||||
m_preallocatedClients.push_back(client);
|
||||
uv_close(reinterpret_cast<uv_handle_t*>(&client->m_socket), on_connection_error);
|
||||
return;
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue