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

Side by Side Diff: Source/wtf/text/StringImpl.cpp

Issue 23901002: [blink]: Annotate StringImpl::createStatic leak for LeakSanitizer. (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Created 7 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
OLDNEW
1 /* 1 /*
2 * Copyright (C) 1999 Lars Knoll (knoll@kde.org) 2 * Copyright (C) 1999 Lars Knoll (knoll@kde.org)
3 * (C) 1999 Antti Koivisto (koivisto@kde.org) 3 * (C) 1999 Antti Koivisto (koivisto@kde.org)
4 * (C) 2001 Dirk Mueller ( mueller@kde.org ) 4 * (C) 2001 Dirk Mueller ( mueller@kde.org )
5 * Copyright (C) 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2013 Apple Inc. All r ights reserved. 5 * Copyright (C) 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2013 Apple Inc. All r ights reserved.
6 * Copyright (C) 2006 Andrew Wellington (proton@wiretapped.net) 6 * Copyright (C) 2006 Andrew Wellington (proton@wiretapped.net)
7 * 7 *
8 * This library is free software; you can redistribute it and/or 8 * This library is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU Library General Public 9 * modify it under the terms of the GNU Library General Public
10 * License as published by the Free Software Foundation; either 10 * License as published by the Free Software Foundation; either
11 * version 2 of the License, or (at your option) any later version. 11 * version 2 of the License, or (at your option) any later version.
12 * 12 *
13 * This library is distributed in the hope that it will be useful, 13 * This library is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 * Library General Public License for more details. 16 * Library General Public License for more details.
17 * 17 *
18 * You should have received a copy of the GNU Library General Public License 18 * You should have received a copy of the GNU Library General Public License
19 * along with this library; see the file COPYING.LIB. If not, write to 19 * along with this library; see the file COPYING.LIB. If not, write to
20 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, 20 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
21 * Boston, MA 02110-1301, USA. 21 * Boston, MA 02110-1301, USA.
22 * 22 *
23 */ 23 */
24 24
25 #include "config.h" 25 #include "config.h"
26 #include "wtf/text/StringImpl.h" 26 #include "wtf/text/StringImpl.h"
27 27
28 #include "wtf/LeakAnnotations.h"
28 #include "wtf/StdLibExtras.h" 29 #include "wtf/StdLibExtras.h"
29 #include "wtf/text/AtomicString.h" 30 #include "wtf/text/AtomicString.h"
30 #include "wtf/text/StringBuffer.h" 31 #include "wtf/text/StringBuffer.h"
31 #include "wtf/text/StringHash.h" 32 #include "wtf/text/StringHash.h"
32 #include "wtf/unicode/CharacterNames.h" 33 #include "wtf/unicode/CharacterNames.h"
33 34
34 #ifdef STRING_STATS 35 #ifdef STRING_STATS
35 #include "wtf/DataLog.h" 36 #include "wtf/DataLog.h"
36 #include "wtf/MainThread.h" 37 #include "wtf/MainThread.h"
37 #include "wtf/ProcessID.h" 38 #include "wtf/ProcessID.h"
(...skipping 300 matching lines...) Expand 10 before | Expand all | Expand 10 after
338 StringImpl* StringImpl::createStatic(const char* string, unsigned length, unsign ed hash) 339 StringImpl* StringImpl::createStatic(const char* string, unsigned length, unsign ed hash)
339 { 340 {
340 ASSERT(string); 341 ASSERT(string);
341 ASSERT(length); 342 ASSERT(length);
342 343
343 // Allocate a single buffer large enough to contain the StringImpl 344 // Allocate a single buffer large enough to contain the StringImpl
344 // struct as well as the data which it contains. This removes one 345 // struct as well as the data which it contains. This removes one
345 // heap allocation from this call. 346 // heap allocation from this call.
346 RELEASE_ASSERT(length <= ((std::numeric_limits<unsigned>::max() - sizeof(Str ingImpl)) / sizeof(LChar))); 347 RELEASE_ASSERT(length <= ((std::numeric_limits<unsigned>::max() - sizeof(Str ingImpl)) / sizeof(LChar)));
347 size_t size = sizeof(StringImpl) + length * sizeof(LChar); 348 size_t size = sizeof(StringImpl) + length * sizeof(LChar);
348 StringImpl* impl = static_cast<StringImpl*>(fastMalloc(size)); 349 StringImpl* impl;
349 350 {
abarth-chromium 2013/09/04 17:34:15 I don't think we need this inner scope. There's o
350 LChar* data = reinterpret_cast<LChar*>(impl + 1); 351 WTF_ANNOTATE_SCOPED_MEMORY_LEAK;
351 impl = new (NotNull, impl) StringImpl(length, hash, StaticString); 352 impl = static_cast<StringImpl*>(fastMalloc(size));
352 memcpy(data, string, length * sizeof(LChar)); 353 LChar* data = reinterpret_cast<LChar*>(impl + 1);
354 impl = new (NotNull, impl) StringImpl(length, hash, StaticString);
355 memcpy(data, string, length * sizeof(LChar));
356 }
353 #ifndef NDEBUG 357 #ifndef NDEBUG
354 impl->assertHashIsCorrect(); 358 impl->assertHashIsCorrect();
355 #endif 359 #endif
356 return impl; 360 return impl;
357 } 361 }
358 362
359 PassRefPtr<StringImpl> StringImpl::create(const UChar* characters, unsigned leng th) 363 PassRefPtr<StringImpl> StringImpl::create(const UChar* characters, unsigned leng th)
360 { 364 {
361 if (!characters || !length) 365 if (!characters || !length)
362 return empty(); 366 return empty();
(...skipping 1606 matching lines...) Expand 10 before | Expand all | Expand 10 after
1969 1973
1970 size_t StringImpl::sizeInBytes() const 1974 size_t StringImpl::sizeInBytes() const
1971 { 1975 {
1972 size_t size = length(); 1976 size_t size = length();
1973 if (!is8Bit()) 1977 if (!is8Bit())
1974 size *= 2; 1978 size *= 2;
1975 return size + sizeof(*this); 1979 return size + sizeof(*this);
1976 } 1980 }
1977 1981
1978 } // namespace WTF 1982 } // namespace WTF
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698