From 649b596531bbd286004ae718c795970ad98d0a1a Mon Sep 17 00:00:00 2001 From: "tc@google.com" Date: Fri, 3 Oct 2008 21:33:05 +0000 Subject: Fix a DocumentLoader leak by switching from using new to a create method that returns a PassRefPtr. This matches what happens in the Apple windows port. I also changed the RefCounted.h deref() to be more like upstream, but it doesn't actually change how RefCounted works. Also bring the JSC RefCounted to be just like upstream. Review URL: http://codereview.chromium.org/6461 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@2855 0039d316-1c4b-4281-b951-d872f2087c98 --- webkit/pending/wtf/RefCounted.h | 22 +++++++++++++--------- 1 file changed, 13 insertions(+), 9 deletions(-) (limited to 'webkit/pending') diff --git a/webkit/pending/wtf/RefCounted.h b/webkit/pending/wtf/RefCounted.h index ecadc0f..256024c 100644 --- a/webkit/pending/wtf/RefCounted.h +++ b/webkit/pending/wtf/RefCounted.h @@ -54,12 +54,14 @@ public: void deref() { ASSERT(!m_deletionHasBegun); - if (--m_refCount <= 0 && !m_peer) { + ASSERT(m_refCount > 0); + if (m_refCount == 1 && !m_peer) { #ifndef NDEBUG m_deletionHasBegun = true; #endif delete static_cast(this); - } + } else + --m_refCount; } void setPeer(void* peer) @@ -76,7 +78,7 @@ public: void* peer() const { return m_peer; } - bool hasOneRef() + bool hasOneRef() const { ASSERT(!m_deletionHasBegun); if (m_peer) @@ -105,7 +107,7 @@ private: template class RefCounted : Noncopyable { public: - RefCounted(int initialRefCount = 0) + RefCounted(int initialRefCount = 1) : m_refCount(initialRefCount) #ifndef NDEBUG , m_deletionHasBegun(false) @@ -122,15 +124,17 @@ public: void deref() { ASSERT(!m_deletionHasBegun); - if (--m_refCount <= 0) { + ASSERT(m_refCount > 0); + if (m_refCount == 1) { #ifndef NDEBUG m_deletionHasBegun = true; -#endif - delete static_cast(this); - } +#endif + delete static_cast(this); + } else + --m_refCount; } - bool hasOneRef() + bool hasOneRef() const { ASSERT(!m_deletionHasBegun); return m_refCount == 1; -- cgit v1.1