-
Notifications
You must be signed in to change notification settings - Fork 1.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[SR-2879] Creating 4 calendars results in an assertion failure #3924
Comments
Looking through a debugger, the error seems to happen when deallocating kFCEmptyString: ``` This is where we are when we're just about to throw an assertion failure: ``` At this point %rdi claims to point to kCFEmptyString: ``` It looks like it's coming from the free of the localeID: ``` |
It looks like the kCFEmptyString's retain count is steadily decreasing. : p (int)swift_retainCount(&__kCFEmptyString) {{ |
Comment by W S (JIRA) |
Not sure that it's definitely related. The Calendar appears to be using kCFEmptyString for its default locale, and it doesn't look like the CF constant strings use an infinite retain count to prevent them from being removed: I believe the error is that 'swift_release' on CF constants causes them to be removed: 1> import Foundation The Swift compiler doesn't get a look in at this point, since the Calendar is doing its own retain/release under the covers. However, the original implementation was written such that it expected that the constants to never be able to be released ... |
OK, I can fix it with an inserted CFRetain for the locale: 1> import Foundation |
Pushed #675 to fix |
Additional Detail from JIRA
md5: 6c8273abf9d22068045fc840a683dc37
relates to:
Issue Description:
This code fails on Linux when assertions are enabled in a build:
```
$ swift-dev/usr/bin/swift
Welcome to Swift version 3.0-dev (LLVM b9bd56d1b8, Clang de97de0726, Swift 44b8a0bd12). Type :help for assistance.
1> import Foundation
2. _ = Calendar(identifier:.buddhist)
3. _ = Calendar(identifier:.chinese)
4. _ = Calendar(identifier:.islamic)
5. _ = Calendar(identifier:.gregorian)
repl_swift: /home/ablewitt/swift-build/swift/include/swift/Runtime/../../../stdlib/public/SwiftShims/RefCount.h:252: bool StrongRefCount::doDecrementShouldDeallocate() [ClearPinnedFlag = false]: Assertion `newval + quantum >= RC_ONE && "releasing reference with a refcount of zero"' failed.
Execution interrupted. Enter code to recover and continue.
Enter LLDB commands to investigate (type :help for assistance.)
6> :bt
thread Fixing whitespace formatting #1: tid = 4412, 0x00007ffff6d88418 libc.so.6`__GI_raise(sig=6) + 56 at raise.c:54, name = 'repl_swift', stop reason = signal SIGABRT
frame #0: 0x00007ffff6d88418 libc.so.6`__GI_raise(sig=6) + 56 at raise.c:54
frame Fixing whitespace formatting #1: 0x00007ffff6d8a01a libc.so.6`__GI_abort + 362 at abort.c:89
frame Fixing grammar issue #2: 0x00007ffff6d80bd7 libc.so.6`__assert_fail_base(fmt="", assertion=<unavailable>, file=<unavailable>, line=<unavailable>, function=<unavailable>) + 279 at assert.c:92
frame Syntax highlighting in README.md #3: 0x00007ffff6d80c82 libc.so.6`GI_assert_fail(assertion=<unavailable>, file=<unavailable>, line=<unavailable>, function=<unavailable>) + 66 at assert.c:101
frame Add @noescape to Synchronous Enumeration, Predicate, and Comparator Blocks #4: 0x00007ffff7ceb790 libswiftCore.so`swift_release + 80
frame Verify contents of the file attributes dictionary #5: 0x00007ffff3d9242e libFoundation.so`__CFCalendarDeallocate + 46
frame Fix URL in README.md #6: 0x00007ffff3ef790e libFoundation.so`Foundation.NSCalendar.__deallocating_deinit + 14
frame Use Correct Source Index in NSArray.getObjects #7: 0x00007ffff4259372 libFoundation.so`Foundation.MutableHandle._deallocating_deinit + 18
frame [WIP] Implement NSRangeFromString #8: 0x00007ffff7f6a098 $__lldb_expr2`main + 136
frame Use Array.reserveCapacity in NSArray/NSMutableArray #9: 0x00000000004009c0 repl_swift`swift_once + 16
frame Fix download link #10: 0x00007fffffffecc0
frame Fix a bug in CFReadStreamGetBuffer for data streams #11: 0x00007ffff6d73830 libc.so.6`__libc_start_main(main=(repl_swift`main), argc=1, argv=0x00007fffffffee38, init=<unavailable>, fini=<unavailable>, rtld_fini=<unavailable>, stack_end=0x00007fffffffee28) + 240 at libc-start.c:291
frame Several NSString constructors implemented #12: 0x00000000004009e9 repl_swift`_start + 41
6>
```
If assertions are disabled, then the code appears to work (but we may have a use-after-free). Running the same code after the failure occurs results in success. It doesn't appear to matter which calendar identifiers are used (provided that they are different to each other)
The text was updated successfully, but these errors were encountered: