Authserver: Fix a memory leak
This commit is contained in:
1 parent
0d80fee45a
commit
c9a462c693
2 files changed
+24
-5
No files matched your search
@@ -30,7 +30,7 @@ public:
|
|||||||
|
|
||||||
AsyncAcceptor(boost::asio::io_service& ioService, std::string const& bindIp, uint16 port) :
|
AsyncAcceptor(boost::asio::io_service& ioService, std::string const& bindIp, uint16 port) :
|
||||||
_acceptor(ioService, tcp::endpoint(boost::asio::ip::address::from_string(bindIp), port)),
|
_acceptor(ioService, tcp::endpoint(boost::asio::ip::address::from_string(bindIp), port)),
|
||||||
_socket(ioService)
|
_socket(ioService), _closed(false)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -54,14 +54,24 @@ public:
|
|||||||
TC_LOG_INFO("network", "Failed to initialize client's socket %s", err.what());
|
TC_LOG_INFO("network", "Failed to initialize client's socket %s", err.what());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if (!_closed)
|
||||||
AsyncAcceptManaged(mgrHandler);
|
AsyncAcceptManaged(mgrHandler);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void Close()
|
||||||
|
{
|
||||||
|
if (_closed.exchange(true))
|
||||||
|
return;
|
||||||
|
|
||||||
|
boost::system::error_code err;
|
||||||
|
_acceptor.close(err);
|
||||||
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
tcp::acceptor _acceptor;
|
tcp::acceptor _acceptor;
|
||||||
tcp::socket _socket;
|
tcp::socket _socket;
|
||||||
|
std::atomic<bool> _closed;
|
||||||
};
|
};
|
||||||
|
|
||||||
template<class T>
|
template<class T>
|
||||||
@@ -83,7 +93,8 @@ void AsyncAcceptor::AsyncAccept()
|
|||||||
}
|
}
|
||||||
|
|
||||||
// lets slap some more this-> on this so we can fix this bug with gcc 4.7.2 throwing internals in yo face
|
// lets slap some more this-> on this so we can fix this bug with gcc 4.7.2 throwing internals in yo face
|
||||||
this->AsyncAccept<T>();
|
if (!_closed)
|
||||||
|
this->AsyncAccept<T>();
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -33,7 +33,7 @@ class SocketMgr
|
|||||||
public:
|
public:
|
||||||
virtual ~SocketMgr()
|
virtual ~SocketMgr()
|
||||||
{
|
{
|
||||||
delete[] _threads;
|
ASSERT(!_threads && !_acceptor && !_threadCount, "StopNetwork must be called prior to SocketMgr destruction");
|
||||||
}
|
}
|
||||||
|
|
||||||
virtual bool StartNetwork(boost::asio::io_service& service, std::string const& bindIp, uint16 port)
|
virtual bool StartNetwork(boost::asio::io_service& service, std::string const& bindIp, uint16 port)
|
||||||
@@ -68,10 +68,18 @@ public:
|
|||||||
|
|
||||||
virtual void StopNetwork()
|
virtual void StopNetwork()
|
||||||
{
|
{
|
||||||
|
_acceptor->Close();
|
||||||
|
|
||||||
if (_threadCount != 0)
|
if (_threadCount != 0)
|
||||||
for (int32 i = 0; i < _threadCount; ++i)
|
for (int32 i = 0; i < _threadCount; ++i)
|
||||||
_threads[i].Stop();
|
_threads[i].Stop();
|
||||||
|
|
||||||
|
delete _acceptor;
|
||||||
|
_acceptor = nullptr;
|
||||||
|
delete[] _threads;
|
||||||
|
_threads = nullptr;
|
||||||
|
_threadCount = 0;
|
||||||
|
|
||||||
Wait();
|
Wait();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in new issue
Block a user