Skip to content

Commit 03ecd63

Browse files
committed
Fixes issue swiftlang#4642: Encountering "Constant strings cannot be deallocated" in Linux foundation
The reported error was an CFSTR("") which is later released. While this should not be a problem, the Linux implementation of CFSTR does not ignore dealloc on constant strings. Fixed this by calling CFRetain on the constant string. Strictly speaking this is only a workaround. Issue swiftlang#1351 has some hints how this could be fixed but the workaround is used a over the code so I think it is okay to use it here, too. I found the same problem in CFDateIntervalFormatter.c where it appeared in a error handling code path that should never be called. Fixed anyways.
1 parent de5f7ed commit 03ecd63

File tree

2 files changed

+3
-3
lines changed

2 files changed

+3
-3
lines changed

CoreFoundation/Locale.subproj/CFDateIntervalFormatter.c

+2-2
Original file line numberDiff line numberDiff line change
@@ -507,7 +507,7 @@ void _CFDateIntervalFormatterSetBoundaryStyle(CFDateIntervalFormatterRef formatt
507507
CFStringRef CFDateIntervalFormatterCreateStringFromDateToDate(CFDateIntervalFormatterRef formatter, CFDateRef fromDate, CFDateRef toDate) {
508508
LOCK();
509509

510-
CFStringRef resultStr = CFSTR("");
510+
CFStringRef resultStr = NULL;
511511
updateFormatter(formatter);
512512

513513
if (formatter->_formatter) {
@@ -531,7 +531,7 @@ CFStringRef CFDateIntervalFormatterCreateStringFromDateToDate(CFDateIntervalForm
531531
resultStr = CFStringCreateWithCharacters(kCFAllocatorSystemDefault, result, len);
532532
}
533533
} else {
534-
resultStr = CFSTR("");
534+
resultStr = (CFStringRef)CFRetain(CFSTR(""));
535535
}
536536
UNLOCK();
537537

CoreFoundation/PlugIn.subproj/CFBundle_Resources.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -1242,7 +1242,7 @@ CF_EXPORT CFTypeRef _Nullable _CFBundleCopyFindResources(CFBundleRef _Nullable b
12421242
if (returnValue) CFRelease(returnValue);
12431243
if ((bundleVersion == _CFBundleVersionOldStyleResources && realSubdirectory && CFEqual(realSubdirectory, CFSTR("Resources"))) || (bundleVersion == _CFBundleVersionContentsResources && realSubdirectory && CFEqual(realSubdirectory, CFSTR("Contents/Resources")))) {
12441244
if (realSubdirectory) CFRelease(realSubdirectory);
1245-
realSubdirectory = CFSTR("");
1245+
realSubdirectory = (CFStringRef)CFRetain(CFSTR(""));
12461246
} else if (bundleVersion == _CFBundleVersionOldStyleResources && realSubdirectory && CFStringGetLength(realSubdirectory) > 10 && CFStringHasPrefix(realSubdirectory, CFSTR("Resources/"))) {
12471247
CFStringRef tmpRealSubdirectory = CFStringCreateWithSubstring(kCFAllocatorSystemDefault, realSubdirectory, CFRangeMake(10, CFStringGetLength(realSubdirectory) - 10));
12481248
if (realSubdirectory) CFRelease(realSubdirectory);

0 commit comments

Comments
 (0)