Description
Previous ID | SR-2879 |
Radar | None |
Original Reporter | @alblue |
Type | Bug |
Status | Resolved |
Resolution | Done |
Additional Detail from JIRA
Votes | 0 |
Component/s | Foundation |
Labels | Bug |
Assignee | @alblue |
Priority | Medium |
md5: 6c8273abf9d22068045fc840a683dc37
relates to:
- SR-2462 Compiler is sometimes overreleasing CF objects
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)