Changeset 221583 in webkit for trunk/Source/JavaScriptCore/API


Ignore:
Timestamp:
Sep 4, 2017, 2:24:21 AM (8 years ago)
Author:
Yusuke Suzuki
Message:

Remove "malloc" and "free" use
https://bugs.webkit.org/show_bug.cgi?id=176310

Reviewed by Darin Adler.

Source/JavaScriptCore:

Use Vector instead.

  • API/JSWrapperMap.mm:

(selectorToPropertyName):

Source/WebCore:

Use MallocPtr<>, fastMalloc/fastFree, or Vector instead of manual call of system malloc/free.
In this patch, we apply the above change if we can easily find the pair of malloc/free.
And we do not touch plugin directory since the external code could call free() onto the
fastMalloc-ed memory.

Also, we still use malloc if the system adopts the allocated memory. Later, the system
will deallocate it by calling the system "free".

  • platform/audio/mac/FFTFrameMac.cpp:

(WebCore::FFTFrame::fftSetupForSize):
(WebCore::FFTFrame::cleanup):

  • platform/graphics/win/FontCacheWin.cpp:

(WebCore::getLinkedFonts):

  • platform/graphics/win/FontCustomPlatformData.cpp:

(WebCore::FontCustomPlatformData::fontPlatformData):

  • platform/graphics/win/FontPlatformDataWin.cpp:

(WebCore::FontPlatformData::FontPlatformData):

  • platform/mac/WebCoreNSURLExtras.mm:

(WebCore::URLByTruncatingOneCharacterBeforeComponent):
(WebCore::dataForURLComponentType):
(WebCore::URLByRemovingComponentAndSubsequentCharacter):
(WebCore::createStringWithEscapedUnsafeCharacters):
(WebCore::userVisibleString):

  • platform/win/ClipboardUtilitiesWin.cpp:

(WebCore::markupToCFHTML):

Source/WTF:

Use Vector instead.

  • wtf/Assertions.cpp:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/JavaScriptCore/API/JSWrapperMap.mm

    r218379 r221583  
    6363@end
    6464
     65static const constexpr unsigned InitialBufferSize { 256 };
     66
    6567// Default conversion of selectors to property names.
    6668// All semicolons are removed, lowercase letters following a semicolon are capitalized.
     
    7678    // The new string needs to be long enough to hold 'header', plus the remainder of the string, excluding
    7779    // at least one ':', but including a '\0'. (This is conservative if there are more than one ':').
    78     char* buffer = static_cast<char*>(malloc(header + strlen(firstColon + 1) + 1));
     80    Vector<char, InitialBufferSize> buffer(header + strlen(firstColon + 1) + 1);
    7981    // Copy 'header' characters, set output to point to the end of this & input to point past the first ':'.
    80     memcpy(buffer, start, header);
    81     char* output = buffer + header;
     82    memcpy(buffer.data(), start, header);
     83    char* output = buffer.data() + header;
    8284    const char* input = start + header + 1;
    8385
     
    102104    }
    103105done:
    104     NSString *result = [NSString stringWithUTF8String:buffer];
    105     free(buffer);
    106     return result;
     106    return [NSString stringWithUTF8String:buffer.data()];
    107107}
    108108
Note: See TracChangeset for help on using the changeset viewer.