Skip to content

Commit 4f67192

Browse files
committed
Fix leak of the indexes buffer.
1 parent 843e73f commit 4f67192

File tree

1 file changed

+4
-1
lines changed

1 file changed

+4
-1
lines changed

Foundation/NSArray.swift

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -543,14 +543,17 @@ open class NSArray : NSObject, NSCopying, NSMutableCopying, NSSecureCoding, NSCo
543543
}
544544
}
545545

546-
return Array(unsafeUninitializedCapacity: range.length) { (buffer, initializedCount) in
546+
let result = Array<Any>(unsafeUninitializedCapacity: range.length) { (buffer, initializedCount) in
547547
var destinationIndex = 0
548548
for index in indexes {
549549
buffer.baseAddress?.advanced(by: destinationIndex).initialize(to: objects[index])
550550
destinationIndex += 1
551551
}
552552
initializedCount = range.length
553553
}
554+
555+
indexes.deallocate()
556+
return result
554557
}
555558

556559
open func sortedArray(comparator cmptr: (Any, Any) -> ComparisonResult) -> [Any] {

0 commit comments

Comments
 (0)