Skip to content

Commit 44c2291

Browse files
authored
Merge pull request #200 from weissi/jw-SR-3628
don't hold references to unowned DispatchData objects (SR-3628)
2 parents 967876e + dac881a commit 44c2291

File tree

2 files changed

+13
-5
lines changed

2 files changed

+13
-5
lines changed

src/swift/DispatchStubs.cc

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -165,6 +165,12 @@ _swift_dispatch_release(dispatch_object_t obj) {
165165
dispatch_release(obj);
166166
}
167167

168+
SWIFT_CC(swift) DISPATCH_RUNTIME_STDLIB_INTERFACE
169+
extern "C" void
170+
_swift_dispatch_retain(dispatch_object_t obj) {
171+
dispatch_retain(obj);
172+
}
173+
168174
// DISPATCH_RUNTIME_STDLIB_INTERFACE
169175
// extern "C" dispatch_queue_t
170176
// _swift_apply_current_root_queue() {

src/swift/Wrapper.swift

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -188,21 +188,20 @@ extension DispatchSource : DispatchSourceProcess,
188188

189189
internal class __DispatchData : DispatchObject {
190190
internal let __wrapped:dispatch_data_t
191-
internal let __owned:Bool
192191

193192
final internal override func wrapped() -> dispatch_object_t {
194193
return unsafeBitCast(__wrapped, to: dispatch_object_t.self)
195194
}
196195

197196
internal init(data:dispatch_data_t, owned:Bool) {
198197
__wrapped = data
199-
__owned = owned
198+
if !owned {
199+
_swift_dispatch_retain(unsafeBitCast(data, to: dispatch_object_t.self))
200+
}
200201
}
201202

202203
deinit {
203-
if __owned {
204-
_swift_dispatch_release(wrapped())
205-
}
204+
_swift_dispatch_release(wrapped())
206205
}
207206
}
208207

@@ -335,3 +334,6 @@ internal enum _OSQoSClass : UInt32 {
335334

336335
@_silgen_name("_swift_dispatch_release")
337336
internal func _swift_dispatch_release(_ obj: dispatch_object_t) -> Void
337+
338+
@_silgen_name("_swift_dispatch_retain")
339+
internal func _swift_dispatch_retain(_ obj: dispatch_object_t) -> Void

0 commit comments

Comments
 (0)