swiftlang / swift-corelibs-foundation

The Foundation Project, providing core utilities, internationalization, and OS independence
swift.org
Apache License 2.0
5.29k stars 1.13k forks source link

`NSCFString` `fatalError("Constant strings cannot be deallocated")` #4804

Open compnerd opened 1 year ago

compnerd commented 1 year ago

When trying to do the following:

print(Bundle.module.url(forResource: "Info", withExtension: "plist", subdirectory: "Resources"))

the fatalError at https://github.com/apple/swift-corelibs-foundation/blob/main/Sources/Foundation/NSCFString.swift#L118-L120 is triggered.

This is due to Bundle.url(forResource:withException:subdirectory:) invoking CFBundleCopyResourceURL, which in turn invokes _CFBundleCopyFindResources, which will run the following:

if (realSubdirectory) CFRelease(realSubdirectory);
compnerd commented 1 year ago

foundation-4804.zip

parkera commented 1 year ago

A difference from Darwin, where releasing constant strings is a no-op...

compnerd commented 1 year ago

I believe that this is impacting Linux as well

compnerd commented 1 year ago

@parkera I think that this might be hinting towards a bridging issue where the bridge between a String and NSCFConstantString does not elide thee release.