Compare commits

...

1 Commits

Author SHA1 Message Date
Koen Schmeets 4e823477a6 Fix leak 2021-06-24 18:33:55 +02:00
1 changed files with 8 additions and 7 deletions

View File

@ -321,15 +321,16 @@ static std::string FilesystemNormalize(const std::string &str) {
std::transform(strW.begin(), strW.end(), strW.begin(), towlower);
return Narrow(strW);
#elif defined(__APPLE__)
CFMutableStringRef cfStr =
CFStringCreateMutableCopy(NULL, 0,
CFStringCreateWithBytesNoCopy(NULL, (const UInt8*)str.data(), str.size(),
kCFStringEncodingUTF8, /*isExternalRepresentation=*/false, kCFAllocatorNull));
CFStringLowercase(cfStr, NULL);
CFStringRef cfStr = CFStringCreateWithBytesNoCopy(NULL, (const UInt8*)str.data(), str.size(),
kCFStringEncodingUTF8, /*isExternalRepresentation=*/false, kCFAllocatorNull);
CFMutableStringRef cfmStr = CFStringCreateMutableCopy(NULL, 0, cfStr);
CFStringLowercase(cfmStr, NULL);
std::string normalizedStr;
normalizedStr.resize(CFStringGetMaximumSizeOfFileSystemRepresentation(cfStr));
CFStringGetFileSystemRepresentation(cfStr, &normalizedStr[0], normalizedStr.size());
normalizedStr.resize(CFStringGetMaximumSizeOfFileSystemRepresentation(cfmStr));
CFStringGetFileSystemRepresentation(cfmStr, &normalizedStr[0], normalizedStr.size());
normalizedStr.erase(normalizedStr.find('\0'));
CFRelease(cfmStr);
CFRelease(cfStr);
return normalizedStr;
#else
return str;