Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(171)

Side by Side Diff: fpdfsdk/cpdfsdk_document.cpp

Issue 2384243002: Guard against double deletion of page views. (Closed)
Patch Set: Created 4 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | fpdfsdk/cpdfsdk_pageview.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2016 PDFium Authors. All rights reserved. 1 // Copyright 2016 PDFium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com 5 // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com
6 6
7 #include "fpdfsdk/cpdfsdk_document.h" 7 #include "fpdfsdk/cpdfsdk_document.h"
8 8
9 #include "core/fpdfapi/fpdf_parser/cpdf_array.h" 9 #include "core/fpdfapi/fpdf_parser/cpdf_array.h"
10 #include "core/fpdfapi/fpdf_parser/cpdf_dictionary.h" 10 #include "core/fpdfapi/fpdf_parser/cpdf_dictionary.h"
(...skipping 117 matching lines...) Expand 10 before | Expand all | Expand 10 after
128 } 128 }
129 return m_pOccontent.get(); 129 return m_pOccontent.get();
130 } 130 }
131 131
132 void CPDFSDK_Document::RemovePageView(UnderlyingPageType* pUnderlyingPage) { 132 void CPDFSDK_Document::RemovePageView(UnderlyingPageType* pUnderlyingPage) {
133 auto it = m_pageMap.find(pUnderlyingPage); 133 auto it = m_pageMap.find(pUnderlyingPage);
134 if (it == m_pageMap.end()) 134 if (it == m_pageMap.end())
135 return; 135 return;
136 136
137 CPDFSDK_PageView* pPageView = it->second; 137 CPDFSDK_PageView* pPageView = it->second;
138 if (pPageView->IsLocked()) 138 if (pPageView->IsLocked() || pPageView->IsBeingDestroyed())
139 return; 139 return;
140 140
141 // Mark the page view so we do not come into |RemovePageView| a second
142 // time while we're in the process of removing.
143 pPageView->SetBeingDestroyed();
Tom Sepez 2016/10/03 18:37:57 Can we this to the dtor? Then the dtor checks for
dsinclair 2016/10/03 18:47:08 No, because we have to guard the map erasing and t
144
141 // This must happen before we remove |pPageView| from the map because 145 // This must happen before we remove |pPageView| from the map because
142 // |KillFocusAnnotIfNeeded| can call into the |GetPage| method which will 146 // |KillFocusAnnotIfNeeded| can call into the |GetPage| method which will
143 // look for this page view in the map, if it doesn't find it a new one will 147 // look for this page view in the map, if it doesn't find it a new one will
144 // be created. We then have two page views pointing to the same page and 148 // be created. We then have two page views pointing to the same page and
145 // bad things happen. 149 // bad things happen.
146 pPageView->KillFocusAnnotIfNeeded(); 150 pPageView->KillFocusAnnotIfNeeded();
147 151
148 // Remove the page from the map to make sure we don't accidentally attempt 152 // Remove the page from the map to make sure we don't accidentally attempt
149 // to use the |pPageView| while we're cleaning it up. 153 // to use the |pPageView| while we're cleaning it up.
150 m_pageMap.erase(it); 154 m_pageMap.erase(it);
(...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after
253 return GetPDFDocument()->GetUserPermissions() & nFlag; 257 return GetPDFDocument()->GetUserPermissions() & nFlag;
254 } 258 }
255 259
256 IJS_Runtime* CPDFSDK_Document::GetJsRuntime() { 260 IJS_Runtime* CPDFSDK_Document::GetJsRuntime() {
257 return m_pEnv->GetJSRuntime(); 261 return m_pEnv->GetJSRuntime();
258 } 262 }
259 263
260 CFX_WideString CPDFSDK_Document::GetPath() { 264 CFX_WideString CPDFSDK_Document::GetPath() {
261 return m_pEnv->JS_docGetFilePath(); 265 return m_pEnv->JS_docGetFilePath();
262 } 266 }
OLDNEW
« no previous file with comments | « no previous file | fpdfsdk/cpdfsdk_pageview.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698