Commit dd5604e7 authored by ggaren@apple.com's avatar ggaren@apple.com

Added an ASSERT to catch an implausible but theoretically possible leak.

        
Reviewed by Dan Bernstein.

In theory, if malloc allocated a UChar buffer directly after a StringImpl,
the StringImpl might incorrecly assume that the UChar buffer was inline,
and fail to delete it.
        
This ASSERT is somewhat academic, since we don't use the same allocator
in debug builds, but oh well.

* platform/text/StringImpl.cpp:
(WebCore::StringImpl::StringImpl):
(WebCore::StringImpl::createUninitialized):
* platform/text/StringImpl.h: Separated the inline buffer StringImpl
constructor from the out-of-line buffer StringImpl constructor. Made
the former ASSERT that its buffer was indeed inline, and the latter ASSERT
that its buffer was indeed not inline.



git-svn-id: svn://svn.chromium.org/blink/trunk@54460 bbb929c8-8fbe-4397-9dbb-9b2b20218538
parent 914d7459
2010-02-05 Geoffrey Garen <ggaren@apple.com>
Reviewed by Dan Bernstein.
Added an ASSERT to catch an implausible but theoretically possible leak.
In theory, if malloc allocated a UChar buffer directly after a StringImpl,
the StringImpl might incorrecly assume that the UChar buffer was inline,
and fail to delete it.
This ASSERT is somewhat academic, since we don't use the same allocator
in debug builds, but oh well.
* platform/text/StringImpl.cpp:
(WebCore::StringImpl::StringImpl):
(WebCore::StringImpl::createUninitialized):
* platform/text/StringImpl.h: Separated the inline buffer StringImpl
constructor from the out-of-line buffer StringImpl constructor. Made
the former ASSERT that its buffer was indeed inline, and the latter ASSERT
that its buffer was indeed not inline.
2010-02-05 Chris Marrin <cmarrin@apple.com>
Reviewed by Simon Fraser.
......
......@@ -97,6 +97,16 @@ inline StringImpl::StringImpl(const UChar* characters, unsigned length)
{
ASSERT(characters);
ASSERT(length);
ASSERT(!bufferIsInternal());
}
inline StringImpl::StringImpl(unsigned length)
: m_data(reinterpret_cast<const UChar*>(this + 1))
, m_length(length)
, m_hash(0)
{
ASSERT(length);
ASSERT(bufferIsInternal());
}
StringImpl::~StringImpl()
......@@ -927,7 +937,7 @@ PassRefPtr<StringImpl> StringImpl::createUninitialized(unsigned length, UChar*&
size_t size = sizeof(StringImpl) + length * sizeof(UChar);
StringImpl* string = static_cast<StringImpl*>(fastMalloc(size));
data = reinterpret_cast<UChar*>(string + 1);
string = new (string) StringImpl(data, length);
string = new (string) StringImpl(length);
return adoptRef(string);
}
......
......@@ -66,9 +66,12 @@ private:
friend class ThreadGlobalData;
StringImpl();
// This adopts the UChar* without copying the buffer.
// This constructor adopts the UChar* without copying the buffer.
StringImpl(const UChar*, unsigned length);
// This constructor assumes that 'this' was allocated with a UChar buffer of size 'length' at the end.
StringImpl(unsigned length);
// For use only by AtomicString's XXXTranslator helpers.
void setHash(unsigned hash) { ASSERT(!m_hash); m_hash = hash; }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment