Skip to content
This repository has been archived by the owner on Dec 28, 2021. It is now read-only.

Commit

Permalink
core: Always use delayed erase in MainLoop
Browse files Browse the repository at this point in the history
If removeCallback() was called from the handler of another file event,
the iterator in run() could become broken.

Fixes #40
  • Loading branch information
flynd committed Dec 5, 2013
1 parent fb75e8e commit 0a9f8d2
Showing 1 changed file with 6 additions and 5 deletions.
11 changes: 6 additions & 5 deletions licq/src/mainloop.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -199,6 +199,9 @@ void MainLoop::run()
{
Private::File& f(i->second);

if (f.removed)
continue;

if (f.pfd == NULL)
/* File has been added after poll was called, just ignore it */
continue;
Expand Down Expand Up @@ -355,9 +358,9 @@ void MainLoop::removeCallback(const MainLoopCallback* callback, bool closeDelete
LICQ_D();

// Find and remove all files with this callback object
for (Private::FileMap::iterator i = d->myFiles.begin(); i != d->myFiles.end(); )
for (Private::FileMap::iterator i = d->myFiles.begin(); i != d->myFiles.end(); ++i)
{
if (i->second.callback == callback)
if (i->second.callback == callback && !i->second.removed)
{
if (closeDelete)
{
Expand All @@ -366,11 +369,9 @@ void MainLoop::removeCallback(const MainLoopCallback* callback, bool closeDelete
else
close(i->second.fd);
}
d->myFiles.erase(i++);
i->second.removed = true;
d->myFilesHasChanged = true;
}
else
++i;
}

// Find and remove all timeouts with this callback object
Expand Down

0 comments on commit 0a9f8d2

Please sign in to comment.