From 97e228c38f312e455e50784146e8a76da7790f97 Mon Sep 17 00:00:00 2001 From: Mike Buland Date: Mon, 14 Jun 2010 21:26:43 +0000 Subject: Fixed a minor memory leak in the server. It makes a difference on popular servers that run for weeks or more. --- src/client.cpp | 1 + src/server.cpp | 29 ++++++++++++++--------------- src/server.h | 1 + 3 files changed, 16 insertions(+), 15 deletions(-) diff --git a/src/client.cpp b/src/client.cpp index 88eb49d..095dd91 100644 --- a/src/client.cpp +++ b/src/client.cpp @@ -33,6 +33,7 @@ Bu::Client::~Client() delete *i; } pTopStream = pSocket = NULL; + delete pfLink; } void Bu::Client::processInput() diff --git a/src/server.cpp b/src/server.cpp index 64ddf9f..51c056a 100644 --- a/src/server.cpp +++ b/src/server.cpp @@ -84,10 +84,7 @@ void Bu::Server::scan() pClient->processInput(); if( !pClient->isOpen() ) { - onClosedConnection( pClient ); - pClient->close(); - hClients.erase( j ); - FD_CLR( j, &fdActive ); + closeClient( j ); } } } @@ -102,10 +99,7 @@ void Bu::Server::scan() } catch( Bu::SocketException &e ) { - onClosedConnection( pClient ); - pClient->close(); - hClients.erase( j ); - FD_CLR( j, &fdActive ); + closeClient( j ); } } catch( Bu::HashException &e ) @@ -130,11 +124,7 @@ void Bu::Server::scan() for( Bu::List::iterator i = lDelete.begin(); i != lDelete.end(); i++ ) { - Client *pClient = hClients.get( *i ); - onClosedConnection( pClient ); - pClient->close(); - hClients.erase( *i ); - FD_CLR( *i, &fdActive ); + closeClient( *i ); } if( bAutoTick ) @@ -206,10 +196,19 @@ void Bu::Server::shutdown() for( ClientHash::iterator i = hClients.begin(); i != hClients.end(); i++ ) { - onClosedConnection( *i ); - delete *i; + closeClient( i.getKey() ); } hClients.clear(); } +void Bu::Server::closeClient( int iSocket ) +{ + Bu::Client *pClient = hClients.get( iSocket ); + onClosedConnection( pClient ); + pClient->close(); + hClients.erase( iSocket ); + FD_CLR( iSocket, &fdActive ); + delete pClient; +} + diff --git a/src/server.h b/src/server.h index e09246f..74ee99a 100644 --- a/src/server.h +++ b/src/server.h @@ -72,6 +72,7 @@ namespace Bu void shutdown(); private: + void closeClient( int iSocket ); class SrvClientLink : public Bu::ClientLink { public: -- cgit v1.2.3