Ignore:
Timestamp:
Sep 12, 2007, 7:16:50 PM (18 years ago)
Author:
weinig
Message:

Reviewed by Geoffrey Garen.

<rdar://problem/5478717> JSStringCreateWithCFString leaks when passed a zero length CFStringRef

  • API/JSStringRefCF.cpp: (JSStringCreateWithCFString): Special case the zero length string and remove the UTF16 optimized path since it will always leak due to the fact that we won't be able to free the backing store that the CFStringRef provides.
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/JavaScriptCore/API/JSStringRefCF.cpp

    r19059 r25527  
    4040    JSLock lock;
    4141    CFIndex length = CFStringGetLength(string);
    42    
    43     // Optimized path for when CFString backing store is a UTF16 buffer
    44     if (const UniChar* buffer = CFStringGetCharactersPtr(string)) {
    45         UString::Rep* rep = UString(reinterpret_cast<const UChar*>(buffer), length).rep()->ref();
    46         return toRef(rep);
     42    UString::Rep* rep;
     43    if (!length)
     44        rep = UString("").rep()->ref();
     45    else {
     46        UniChar* buffer = static_cast<UniChar*>(fastMalloc(sizeof(UniChar) * length));
     47        CFStringGetCharacters(string, CFRangeMake(0, length), buffer);
     48        rep = UString(reinterpret_cast<UChar*>(buffer), length, false).rep()->ref();
    4749    }
    48 
    49     UniChar* buffer = static_cast<UniChar*>(fastMalloc(sizeof(UniChar) * length));
    50     CFStringGetCharacters(string, CFRangeMake(0, length), buffer);
    51     UString::Rep* rep = UString(reinterpret_cast<UChar*>(buffer), length, false).rep()->ref();
    5250    return toRef(rep);
    5351}
Note: See TracChangeset for help on using the changeset viewer.