Fixed weak ptr deref bug.

This commit is contained in:
Gunnar Beutner 2012-04-20 16:21:43 +02:00
parent 5ae2c4aa5b
commit 90c4d6624b
2 changed files with 21 additions and 9 deletions

View File

@ -59,11 +59,17 @@ void Application::RunEventLoop(void)
FD_ZERO(&writefds);
FD_ZERO(&exceptfds);
for (Socket::CollectionType::iterator i = Socket::Sockets.begin(); i != Socket::Sockets.end(); i++) {
Socket::CollectionType::iterator prev, i;
for (i = Socket::Sockets.begin(); i != Socket::Sockets.end(); ) {
Socket::Ptr socket = i->lock();
if (socket == NULL)
prev = i;
i++;
if (!socket) {
Socket::Sockets.erase(prev);
continue;
}
int fd = socket->GetFD();
@ -106,15 +112,16 @@ void Application::RunEventLoop(void)
EventArgs ea;
ea.Source = shared_from_this();
Socket::CollectionType::iterator prev, i;
for (i = Socket::Sockets.begin(); i != Socket::Sockets.end(); ) {
Socket::Ptr socket = i->lock();
prev = i;
i++;
Socket::Ptr socket = prev->lock();
if (socket == NULL)
if (!socket) {
Socket::Sockets.erase(prev);
continue;
}
int fd = socket->GetFD();

View File

@ -42,12 +42,17 @@ void Timer::CallExpiredTimers(void)
time(&now);
for (Timer::CollectionType::iterator i = Timers.begin(); i != Timers.end(); ) {
Timer::Ptr timer = Timer::Ptr(*i);
Timer::CollectionType::iterator prev, i;
for (i = Timers.begin(); i != Timers.end(); ) {
Timer::Ptr timer = i->lock();
prev = i;
i++;
if (timer == NULL)
if (!timer) {
Timers.erase(prev);
continue;
}
if (timer->m_Next <= now) {
timer->Call();