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

View File

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