aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorMike Buland <eichlan@xagasoft.com>2010-06-14 21:26:43 +0000
committerMike Buland <eichlan@xagasoft.com>2010-06-14 21:26:43 +0000
commit97e228c38f312e455e50784146e8a76da7790f97 (patch)
treee9fbee7a7d64797d2cae233eb7eb6b5d75d34117 /src
parent5e5fa99148a14f45d162b43dfbf31db3eb110f0d (diff)
downloadlibbu++-97e228c38f312e455e50784146e8a76da7790f97.tar.gz
libbu++-97e228c38f312e455e50784146e8a76da7790f97.tar.bz2
libbu++-97e228c38f312e455e50784146e8a76da7790f97.tar.xz
libbu++-97e228c38f312e455e50784146e8a76da7790f97.zip
Fixed a minor memory leak in the server. It makes a difference on popular
servers that run for weeks or more.
Diffstat (limited to 'src')
-rw-r--r--src/client.cpp1
-rw-r--r--src/server.cpp29
-rw-r--r--src/server.h1
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()
33 delete *i; 33 delete *i;
34 } 34 }
35 pTopStream = pSocket = NULL; 35 pTopStream = pSocket = NULL;
36 delete pfLink;
36} 37}
37 38
38void Bu::Client::processInput() 39void 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()
84 pClient->processInput(); 84 pClient->processInput();
85 if( !pClient->isOpen() ) 85 if( !pClient->isOpen() )
86 { 86 {
87 onClosedConnection( pClient ); 87 closeClient( j );
88 pClient->close();
89 hClients.erase( j );
90 FD_CLR( j, &fdActive );
91 } 88 }
92 } 89 }
93 } 90 }
@@ -102,10 +99,7 @@ void Bu::Server::scan()
102 } 99 }
103 catch( Bu::SocketException &e ) 100 catch( Bu::SocketException &e )
104 { 101 {
105 onClosedConnection( pClient ); 102 closeClient( j );
106 pClient->close();
107 hClients.erase( j );
108 FD_CLR( j, &fdActive );
109 } 103 }
110 } 104 }
111 catch( Bu::HashException &e ) 105 catch( Bu::HashException &e )
@@ -130,11 +124,7 @@ void Bu::Server::scan()
130 124
131 for( Bu::List<int>::iterator i = lDelete.begin(); i != lDelete.end(); i++ ) 125 for( Bu::List<int>::iterator i = lDelete.begin(); i != lDelete.end(); i++ )
132 { 126 {
133 Client *pClient = hClients.get( *i ); 127 closeClient( *i );
134 onClosedConnection( pClient );
135 pClient->close();
136 hClients.erase( *i );
137 FD_CLR( *i, &fdActive );
138 } 128 }
139 129
140 if( bAutoTick ) 130 if( bAutoTick )
@@ -206,10 +196,19 @@ void Bu::Server::shutdown()
206 196
207 for( ClientHash::iterator i = hClients.begin(); i != hClients.end(); i++ ) 197 for( ClientHash::iterator i = hClients.begin(); i != hClients.end(); i++ )
208 { 198 {
209 onClosedConnection( *i ); 199 closeClient( i.getKey() );
210 delete *i;
211 } 200 }
212 201
213 hClients.clear(); 202 hClients.clear();
214} 203}
215 204
205void Bu::Server::closeClient( int iSocket )
206{
207 Bu::Client *pClient = hClients.get( iSocket );
208 onClosedConnection( pClient );
209 pClient->close();
210 hClients.erase( iSocket );
211 FD_CLR( iSocket, &fdActive );
212 delete pClient;
213}
214
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
72 void shutdown(); 72 void shutdown();
73 73
74 private: 74 private:
75 void closeClient( int iSocket );
75 class SrvClientLink : public Bu::ClientLink 76 class SrvClientLink : public Bu::ClientLink
76 { 77 {
77 public: 78 public: