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

Side by Side Diff: core/fpdfapi/fpdf_page/cpdf_countedobject.h

Issue 2364673002: Null CPDF_CountedObj::m_pObj prior to deletion (Closed)
Patch Set: Copy comment from strings header, fix old comment 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 | core/fxcrt/cfx_string_data_template.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 #ifndef CORE_FPDFAPI_FPDF_PAGE_CPDF_COUNTEDOBJECT_H_ 7 #ifndef CORE_FPDFAPI_FPDF_PAGE_CPDF_COUNTEDOBJECT_H_
8 #define CORE_FPDFAPI_FPDF_PAGE_CPDF_COUNTEDOBJECT_H_ 8 #define CORE_FPDFAPI_FPDF_PAGE_CPDF_COUNTEDOBJECT_H_
9 9
10 #include "core/fpdfapi/fpdf_page/cpdf_pattern.h" 10 #include "core/fpdfapi/fpdf_page/cpdf_pattern.h"
11 #include "core/fpdfapi/fpdf_page/include/cpdf_colorspace.h" 11 #include "core/fpdfapi/fpdf_page/include/cpdf_colorspace.h"
12 #include "core/fxcrt/include/fx_system.h" 12 #include "core/fxcrt/include/fx_system.h"
13 13
14 template <class T> 14 template <class T>
15 class CPDF_CountedObject { 15 class CPDF_CountedObject {
16 public: 16 public:
17 explicit CPDF_CountedObject(T* ptr) : m_nCount(1), m_pObj(ptr) {} 17 explicit CPDF_CountedObject(T* ptr) : m_nCount(1), m_pObj(ptr) {}
18 void reset(T* ptr) { // CAUTION: tosses prior ref counts. 18 void reset(T* ptr) { // CAUTION: tosses prior ref counts.
19 m_nCount = 1; 19 m_nCount = 1;
20 m_pObj = ptr; 20 m_pObj = ptr;
21 } 21 }
22 void clear() { // Now you're all weak ptrs ... 22 void clear() { // Now you're all weak ptrs ...
23 delete m_pObj; 23 // Guard against accidental re-entry.
24 T* pObj = m_pObj;
24 m_pObj = nullptr; 25 m_pObj = nullptr;
26 delete pObj;
25 } 27 }
26 T* get() const { return m_pObj; } 28 T* get() const { return m_pObj; }
27 T* AddRef() { 29 T* AddRef() {
28 ASSERT(m_pObj); 30 ASSERT(m_pObj);
29 ++m_nCount; 31 ++m_nCount;
30 return m_pObj; 32 return m_pObj;
31 } 33 }
32 void RemoveRef() { 34 void RemoveRef() {
33 if (m_nCount) 35 if (m_nCount)
34 --m_nCount; 36 --m_nCount;
35 } 37 }
36 size_t use_count() const { return m_nCount; } 38 size_t use_count() const { return m_nCount; }
37 39
38 protected: 40 protected:
39 size_t m_nCount; 41 size_t m_nCount;
40 T* m_pObj; 42 T* m_pObj;
41 }; 43 };
42 using CPDF_CountedColorSpace = CPDF_CountedObject<CPDF_ColorSpace>; 44 using CPDF_CountedColorSpace = CPDF_CountedObject<CPDF_ColorSpace>;
43 using CPDF_CountedPattern = CPDF_CountedObject<CPDF_Pattern>; 45 using CPDF_CountedPattern = CPDF_CountedObject<CPDF_Pattern>;
44 46
45 #endif // CORE_FPDFAPI_FPDF_PAGE_CPDF_COUNTEDOBJECT_H_ 47 #endif // CORE_FPDFAPI_FPDF_PAGE_CPDF_COUNTEDOBJECT_H_
OLDNEW
« no previous file with comments | « no previous file | core/fxcrt/cfx_string_data_template.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698