From 03ecd6327197defb1a4f420b5db038ae0a62d3de Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20H=C3=B6pfl?= Date: Thu, 3 Nov 2022 07:39:04 +0100 Subject: [PATCH] Fixes issue #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 #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. --- CoreFoundation/Locale.subproj/CFDateIntervalFormatter.c | 4 ++-- CoreFoundation/PlugIn.subproj/CFBundle_Resources.c | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/CoreFoundation/Locale.subproj/CFDateIntervalFormatter.c b/CoreFoundation/Locale.subproj/CFDateIntervalFormatter.c index 78c0df3c15..6fe554c85b 100644 --- a/CoreFoundation/Locale.subproj/CFDateIntervalFormatter.c +++ b/CoreFoundation/Locale.subproj/CFDateIntervalFormatter.c @@ -507,7 +507,7 @@ void _CFDateIntervalFormatterSetBoundaryStyle(CFDateIntervalFormatterRef formatt CFStringRef CFDateIntervalFormatterCreateStringFromDateToDate(CFDateIntervalFormatterRef formatter, CFDateRef fromDate, CFDateRef toDate) { LOCK(); - CFStringRef resultStr = CFSTR(""); + CFStringRef resultStr = NULL; updateFormatter(formatter); if (formatter->_formatter) { @@ -531,7 +531,7 @@ CFStringRef CFDateIntervalFormatterCreateStringFromDateToDate(CFDateIntervalForm resultStr = CFStringCreateWithCharacters(kCFAllocatorSystemDefault, result, len); } } else { - resultStr = CFSTR(""); + resultStr = (CFStringRef)CFRetain(CFSTR("")); } UNLOCK(); diff --git a/CoreFoundation/PlugIn.subproj/CFBundle_Resources.c b/CoreFoundation/PlugIn.subproj/CFBundle_Resources.c index c7fb636b71..601d014a73 100644 --- a/CoreFoundation/PlugIn.subproj/CFBundle_Resources.c +++ b/CoreFoundation/PlugIn.subproj/CFBundle_Resources.c @@ -1242,7 +1242,7 @@ CF_EXPORT CFTypeRef _Nullable _CFBundleCopyFindResources(CFBundleRef _Nullable b if (returnValue) CFRelease(returnValue); if ((bundleVersion == _CFBundleVersionOldStyleResources && realSubdirectory && CFEqual(realSubdirectory, CFSTR("Resources"))) || (bundleVersion == _CFBundleVersionContentsResources && realSubdirectory && CFEqual(realSubdirectory, CFSTR("Contents/Resources")))) { if (realSubdirectory) CFRelease(realSubdirectory); - realSubdirectory = CFSTR(""); + realSubdirectory = (CFStringRef)CFRetain(CFSTR("")); } else if (bundleVersion == _CFBundleVersionOldStyleResources && realSubdirectory && CFStringGetLength(realSubdirectory) > 10 && CFStringHasPrefix(realSubdirectory, CFSTR("Resources/"))) { CFStringRef tmpRealSubdirectory = CFStringCreateWithSubstring(kCFAllocatorSystemDefault, realSubdirectory, CFRangeMake(10, CFStringGetLength(realSubdirectory) - 10)); if (realSubdirectory) CFRelease(realSubdirectory);