Index: chrome/browser/extensions/lazy_background_task_queue.cc diff --git a/chrome/browser/extensions/lazy_background_task_queue.cc b/chrome/browser/extensions/lazy_background_task_queue.cc index b98d44626be848a3a2db04c60ac4cb11ea981243..49bc2229325ce5ba975de4d76347a388a598e86d 100644 --- a/chrome/browser/extensions/lazy_background_task_queue.cc +++ b/chrome/browser/extensions/lazy_background_task_queue.cc @@ -115,14 +115,16 @@ void LazyBackgroundTaskQueue::ProcessPendingTasks( return; } - PendingTasksList* tasks = map_it->second.get(); - for (PendingTasksList::const_iterator it = tasks->begin(); - it != tasks->end(); ++it) { + // Swap the pending tasks to a temporary, to avoid problems if the task + // list is modified during processing. + PendingTasksList tasks; + tasks.swap(*map_it->second); + for (PendingTasksList::const_iterator it = tasks.begin(); + it != tasks.end(); ++it) { it->Run(host); } - tasks->clear(); - pending_tasks_.erase(map_it); + pending_tasks_.erase(key); // Balance the keepalive in AddPendingTask. Note we don't do this on a // failure to load, because the keepalive count is reset in that case.