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

Unified 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « core/fxcrt/cfx_string_data_template.h ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: core/fxcrt/include/cfx_count_ref.h
diff --git a/core/fxcrt/include/cfx_count_ref.h b/core/fxcrt/include/cfx_count_ref.h
index d709efb67c0c9d1d64554d507ad0892ec3063c4b..a879967b28ff6c338ec154101743654e3bfa7739 100644
--- a/core/fxcrt/include/cfx_count_ref.h
+++ b/core/fxcrt/include/cfx_count_ref.h
@@ -56,15 +56,22 @@ class CFX_CountRef {
CountedObj(Args... params) : ObjClass(params...), m_RefCount(0) {}
CountedObj(const CountedObj& src) : ObjClass(src), m_RefCount(0) {}
+ ~CountedObj() { m_RefCount = 0; }
bool HasOneRef() const { return m_RefCount == 1; }
void Retain() { m_RefCount++; }
void Release() {
- if (--m_RefCount <= 0)
+ ASSERT(m_RefCount);
+ if (--m_RefCount == 0)
delete this;
}
private:
+ // To ensure ref counts do not overflow, consider the worst possible case:
+ // the entire address space contains nothing but pointers to this object.
+ // Since the count increments with each new pointer, the largest value is
+ // the number of pointers that can fit into the address space. The size of
+ // the address space itself is a good upper bound on it.
intptr_t m_RefCount;
};
« 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