Skip to content

Commit 547fbec

Browse files
committed
Fix continuation memory leak in Ares.query
1 parent 1f5d6f4 commit 547fbec

File tree

1 file changed

+6
-7
lines changed

1 file changed

+6
-7
lines changed

Sources/AsyncDNSResolver/c-ares/DNSResolver_c-ares.swift

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -160,8 +160,12 @@ class Ares {
160160
preconditionFailure("'arg' is nil. This is a bug.")
161161
}
162162

163-
let handler = QueryReplyHandler(pointer: handlerPointer)
164-
defer { handlerPointer.deallocate() }
163+
let pointer = handlerPointer.assumingMemoryBound(to: QueryReplyHandler.self)
164+
let handler = pointer.pointee
165+
defer {
166+
pointer.deinitialize(count: 1)
167+
pointer.deallocate()
168+
}
165169

166170
handler.handle(status: status, buffer: buf, length: len)
167171
}
@@ -276,11 +280,6 @@ extension Ares {
276280
}
277281
}
278282

279-
init(pointer: UnsafeMutableRawPointer) {
280-
let handlerPointer = pointer.assumingMemoryBound(to: Self.self)
281-
self = handlerPointer.pointee
282-
}
283-
284283
func handle(status: CInt, buffer: UnsafeMutablePointer<CUnsignedChar>?, length: CInt) {
285284
self._handler(status, buffer, length)
286285
}

0 commit comments

Comments
 (0)