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

Side by Side Diff: core/fxcrt/include/cfx_count_ref.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, 3 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 | « core/fxcrt/cfx_string_data_template.h ('k') | no next file » | 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_FXCRT_INCLUDE_CFX_COUNT_REF_H_ 7 #ifndef CORE_FXCRT_INCLUDE_CFX_COUNT_REF_H_
8 #define CORE_FXCRT_INCLUDE_CFX_COUNT_REF_H_ 8 #define CORE_FXCRT_INCLUDE_CFX_COUNT_REF_H_
9 9
10 #include "core/fxcrt/include/cfx_retain_ptr.h" 10 #include "core/fxcrt/include/cfx_retain_ptr.h"
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
49 bool operator!=(const CFX_CountRef& that) const { return !(*this == that); } 49 bool operator!=(const CFX_CountRef& that) const { return !(*this == that); }
50 explicit operator bool() const { return !!m_pObject; } 50 explicit operator bool() const { return !!m_pObject; }
51 51
52 private: 52 private:
53 class CountedObj : public ObjClass { 53 class CountedObj : public ObjClass {
54 public: 54 public:
55 template <typename... Args> 55 template <typename... Args>
56 CountedObj(Args... params) : ObjClass(params...), m_RefCount(0) {} 56 CountedObj(Args... params) : ObjClass(params...), m_RefCount(0) {}
57 57
58 CountedObj(const CountedObj& src) : ObjClass(src), m_RefCount(0) {} 58 CountedObj(const CountedObj& src) : ObjClass(src), m_RefCount(0) {}
59 ~CountedObj() { m_RefCount = 0; }
59 60
60 bool HasOneRef() const { return m_RefCount == 1; } 61 bool HasOneRef() const { return m_RefCount == 1; }
61 void Retain() { m_RefCount++; } 62 void Retain() { m_RefCount++; }
62 void Release() { 63 void Release() {
63 if (--m_RefCount <= 0) 64 ASSERT(m_RefCount);
65 if (--m_RefCount == 0)
64 delete this; 66 delete this;
65 } 67 }
66 68
67 private: 69 private:
70 // To ensure ref counts do not overflow, consider the worst possible case:
71 // the entire address space contains nothing but pointers to this object.
72 // Since the count increments with each new pointer, the largest value is
73 // the number of pointers that can fit into the address space. The size of
74 // the address space itself is a good upper bound on it.
68 intptr_t m_RefCount; 75 intptr_t m_RefCount;
69 }; 76 };
70 77
71 CFX_RetainPtr<CountedObj> m_pObject; 78 CFX_RetainPtr<CountedObj> m_pObject;
72 }; 79 };
73 80
74 #endif // CORE_FXCRT_INCLUDE_CFX_COUNT_REF_H_ 81 #endif // CORE_FXCRT_INCLUDE_CFX_COUNT_REF_H_
OLDNEW
« no previous file with comments | « core/fxcrt/cfx_string_data_template.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698