Commit 01c9a7e7 authored by Dan Sinclair's avatar Dan Sinclair Committed by Commit Bot

[pdf] Use a temporary list when unloading pages

When traversing the |deferred_page_unloads_| list and handling the
unloads it's possible for new pages to get added to the list which will
invalidate the iterator.

This CL swaps the list with an empty list and does the iteration on the
list copy. New items that are unloaded while handling the defers will be
unloaded at a later point.

Bug: 780450
Change-Id: Ic7ced1c82227109784fb536ce19a4dd51b9119ac
Reviewed-on: https://chromium-review.googlesource.com/758916
Commit-Queue: dsinclair <dsinclair@chromium.org>
Reviewed-by: default avatarLei Zhang <thestig@chromium.org>
Cr-Commit-Position: refs/heads/master@{#515056}
parent 345dab42
......@@ -1405,9 +1405,15 @@ bool PDFiumEngine::HandleEvent(const pp::InputEvent& event) {
DCHECK(defer_page_unload_);
defer_page_unload_ = false;
for (int page_index : deferred_page_unloads_)
// Store the pages to unload away because the act of unloading pages can cause
// there to be more pages to unload. We leave those extra pages to be unloaded
// on the next go around.
std::vector<int> pages_to_unload;
std::swap(pages_to_unload, deferred_page_unloads_);
for (int page_index : pages_to_unload)
pages_[page_index]->Unload();
deferred_page_unloads_.clear();
return rv;
}
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment