Skip to content

Commit 0f7e4bf

Browse files
committed
[5.9][Stdlib] Fix bridgedStorage lifetime in SwiftNativeNSArray._destroyBridgedStorage.
Extend the lifetime of bridgedStorage until after the contents are deinitialized. When two threads race in withUnsafeBufferOfObjects, the loser uses _destroyBridgedStorage to destroy its candidate buffer, and we need to extend the lifetime of that buffer since the parameter is the only extant reference to it. rdar://99565140 (cherry picked from commit acbcd5f)
1 parent 17305da commit 0f7e4bf

File tree

1 file changed

+5
-3
lines changed

1 file changed

+5
-3
lines changed

stdlib/public/core/SwiftNativeNSArray.swift

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -367,9 +367,11 @@ extension __SwiftNativeNSArrayWithContiguousStorage {
367367

368368
internal func _destroyBridgedStorage(_ hb: __BridgingBufferStorage?) {
369369
if let bridgedStorage = hb {
370-
let buffer = _BridgingBuffer(bridgedStorage)
371-
let count = buffer.count
372-
buffer.baseAddress.deinitialize(count: count)
370+
withExtendedLifetime(bridgedStorage) {
371+
let buffer = _BridgingBuffer(bridgedStorage)
372+
let count = buffer.count
373+
buffer.baseAddress.deinitialize(count: count)
374+
}
373375
}
374376
}
375377

0 commit comments

Comments
 (0)