Changeset 53575 in webkit
- Timestamp:
- Jan 20, 2010 4:15:27 PM (14 years ago)
- Location:
- trunk/WebCore
- Files:
-
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/WebCore/ChangeLog
r53574 r53575 1 2010-01-20 Gavin Barraclough <barraclough@apple.com> 2 3 Reviewed by NOBODY. 4 5 <rdar://problem/7557695> REGRESSION(r53445-r53449): Many new memory leaks (33867) 6 7 Revert r53447, since this caused leaks. 8 9 * WebCore.base.exp: 10 * platform/text/StringImpl.cpp: 11 (WebCore::StringImpl::operator new): 12 (WebCore::StringImpl::operator delete): 13 (WebCore::StringImpl::StringImpl): 14 (WebCore::StringImpl::~StringImpl): 15 (WebCore::StringImpl::create): 16 (WebCore::StringImpl::createWithTerminatingNullCharacter): 17 (WebCore::StringImpl::crossThreadString): 18 (WebCore::StringImpl::sharedBuffer): 19 * platform/text/StringImpl.h: 20 (WebCore::StringImpl::hasTerminatingNullCharacter): 21 (WebCore::StringImpl::inTable): 22 (WebCore::StringImpl::setInTable): 23 (WebCore::StringImpl::): 24 * storage/OriginUsageRecord.cpp: 25 (WebCore::OriginUsageRecord::addDatabase): 26 (WebCore::OriginUsageRecord::markDatabase): 27 1 28 2010-01-20 Jian Li <jianli@chromium.org> 2 29 -
trunk/WebCore/WebCore.base.exp
r53524 r53575 144 144 __ZN7WebCore10StringImplD1Ev 145 145 __ZN7WebCore10StringImplcvP8NSStringEv 146 __ZN7WebCore10StringImpldlEPv 146 147 __ZN7WebCore10handCursorEv 147 148 __ZN7WebCore10setCookiesEPNS_8DocumentERKNS_4KURLERKNS_6StringE -
trunk/WebCore/platform/text/StringImpl.cpp
r53447 r53575 58 58 } 59 59 60 // Some of the factory methods create buffers using fastMalloc. 61 // We must ensure that all allocations of StringImpl are allocated using 62 // fastMalloc so that we don't have mis-matched frees. We accomplish 63 // this by overriding the new and delete operators. 64 void* StringImpl::operator new(size_t size, void* address) 65 { 66 if (address) 67 return address; // Allocating using an internal buffer 68 return fastMalloc(size); 69 } 70 71 void* StringImpl::operator new(size_t size) 72 { 73 return fastMalloc(size); 74 } 75 76 void StringImpl::operator delete(void* address) 77 { 78 fastFree(address); 79 } 80 60 81 // This constructor is used only to create the empty string. 61 82 StringImpl::StringImpl() 62 83 : m_data(0) 63 , m_sharedBuffer(0)64 84 , m_length(0) 65 , m_refCountAndFlags(s_refCountIncrement)66 85 , m_hash(0) 67 86 { … … 74 93 inline StringImpl::StringImpl(const UChar* characters, unsigned length) 75 94 : m_data(characters) 76 , m_sharedBuffer(0)77 95 , m_length(length) 78 , m_refCountAndFlags(s_refCountIncrement)79 96 , m_hash(0) 80 97 { … … 88 105 AtomicString::remove(this); 89 106 if (!bufferIsInternal()) { 90 SharedUChar* sharedBuffer = m_sharedBuffer ;107 SharedUChar* sharedBuffer = m_sharedBufferAndFlags.get(); 91 108 if (sharedBuffer) 92 109 sharedBuffer->deref(); … … 954 971 PassRefPtr<StringImpl> impl = adoptRef(new StringImpl(str.data(), str.size())); 955 972 sharedBuffer->ref(); 956 impl->m_sharedBuffer = sharedBuffer;973 impl->m_sharedBufferAndFlags.set(sharedBuffer); 957 974 return impl; 958 975 } … … 981 998 terminatedString->m_length--; 982 999 terminatedString->m_hash = string.m_hash; 983 terminatedString->m_ refCountAndFlags |= s_refCountFlagHasTerminatingNullCharacter;1000 terminatedString->m_sharedBufferAndFlags.setFlag(HasTerminatingNullCharacter); 984 1001 return terminatedString.release(); 985 1002 } … … 998 1015 if (shared) { 999 1016 RefPtr<StringImpl> impl = adoptRef(new StringImpl(m_data, m_length)); 1000 impl->m_sharedBuffer = shared->crossThreadCopy().releaseRef();1017 impl->m_sharedBufferAndFlags.set(shared->crossThreadCopy().releaseRef()); 1001 1018 return impl.release(); 1002 1019 } … … 1011 1028 return 0; 1012 1029 1013 if (!m_sharedBuffer )1014 m_sharedBuffer = SharedUChar::create(new OwnFastMallocPtr<UChar>(const_cast<UChar*>(m_data))).releaseRef();1015 return m_sharedBuffer ;1030 if (!m_sharedBufferAndFlags.get()) 1031 m_sharedBufferAndFlags.set(SharedUChar::create(new OwnFastMallocPtr<UChar>(const_cast<UChar*>(m_data))).releaseRef()); 1032 return m_sharedBufferAndFlags.get(); 1016 1033 } 1017 1034 -
trunk/WebCore/platform/text/StringImpl.h
r53447 r53575 27 27 #include <wtf/ASCIICType.h> 28 28 #include <wtf/CrossThreadRefCounted.h> 29 #include <wtf/Noncopyable.h>30 29 #include <wtf/OwnFastMallocPtr.h> 30 #include <wtf/PtrAndFlags.h> 31 31 #include <wtf/RefCounted.h> 32 32 #include <wtf/StringHashFunctions.h> … … 59 59 typedef bool (*CharacterMatchFunctionPtr)(UChar); 60 60 61 class StringImpl : public Noncopyable{61 class StringImpl : public RefCounted<StringImpl> { 62 62 friend struct CStringTranslator; 63 63 friend struct HashAndCharactersTranslator; … … 97 97 unsigned length() { return m_length; } 98 98 99 bool hasTerminatingNullCharacter() const { return m_ refCountAndFlags & s_refCountFlagHasTerminatingNullCharacter; }100 101 bool inTable() const { return m_ refCountAndFlags & s_refCountFlagInTable; }102 void setInTable() { m_refCountAndFlags |= s_refCountFlagInTable; }99 bool hasTerminatingNullCharacter() const { return m_sharedBufferAndFlags.isFlagSet(HasTerminatingNullCharacter); } 100 101 bool inTable() const { return m_sharedBufferAndFlags.isFlagSet(InTable); } 102 void setInTable() { return m_sharedBufferAndFlags.setFlag(InTable); } 103 103 104 104 unsigned hash() { if (m_hash == 0) m_hash = computeHash(m_data, m_length); return m_hash; } … … 107 107 inline static unsigned computeHash(const char* data) { return WTF::stringHash(data); } 108 108 109 StringImpl* ref() { m_refCountAndFlags += s_refCountIncrement; return this; }110 ALWAYS_INLINE void deref() { m_refCountAndFlags -= s_refCountIncrement; if (!(m_refCountAndFlags & s_refCountMask)) delete this; }111 ALWAYS_INLINE bool hasOneRef() const { return (m_refCountAndFlags & s_refCountMask) == s_refCountIncrement; }112 113 109 // Returns a StringImpl suitable for use on another thread. 114 110 PassRefPtr<StringImpl> crossThreadString(); … … 180 176 #endif 181 177 178 void operator delete(void*); 179 182 180 private: 183 using Noncopyable::operator new; 184 void* operator new(size_t, void* inPlace) { ASSERT(inPlace); return inPlace; } 181 // Allocation from a custom buffer is only allowed internally to avoid 182 // mismatched allocators. Callers should use create(). 183 void* operator new(size_t size); 184 void* operator new(size_t size, void* address); 185 185 186 186 static PassRefPtr<StringImpl> createStrippingNullCharactersSlowCase(const UChar*, unsigned length); … … 190 190 bool bufferIsInternal() { return m_data == reinterpret_cast<const UChar*>(this + 1); } 191 191 192 static const unsigned s_refCountMask = 0xFFFFFFFC;193 static const unsigned s_refCountIncrement = 0x4;194 static const unsigned s_refCountFlagHasTerminatingNullCharacter = 0x2;195 static const unsigned s_refCountFlagInTable = 0x1;192 enum StringImplFlags { 193 HasTerminatingNullCharacter, 194 InTable, 195 }; 196 196 197 197 const UChar* m_data; 198 SharedUChar* m_sharedBuffer;199 198 unsigned m_length; 200 unsigned m_refCountAndFlags;201 199 mutable unsigned m_hash; 200 PtrAndFlags<SharedUChar, StringImplFlags> m_sharedBufferAndFlags; 202 201 // There is a fictitious variable-length UChar array at the end, which is used 203 202 // as the internal buffer by the createUninitialized and create methods. -
trunk/WebCore/storage/OriginUsageRecord.cpp
r53447 r53575 43 43 { 44 44 ASSERT(!m_databaseMap.contains(identifier)); 45 ASSERT_ARG(identifier, identifier.impl()-> hasOneRef());46 ASSERT_ARG(fullPath, fullPath.impl()-> hasOneRef());45 ASSERT_ARG(identifier, identifier.impl()->refCount() == 1); 46 ASSERT_ARG(fullPath, fullPath.impl()->refCount() == 1); 47 47 48 48 m_databaseMap.set(identifier, DatabaseEntry(fullPath)); … … 64 64 { 65 65 ASSERT(m_databaseMap.contains(identifier)); 66 ASSERT_ARG(identifier, identifier.impl()-> hasOneRef());66 ASSERT_ARG(identifier, identifier.impl()->refCount() == 1); 67 67 68 68 m_unknownSet.add(identifier);
Note: See TracChangeset
for help on using the changeset viewer.