Skip to content

Commit 1fc0f3c

Browse files
committed
[Distributed] Runtime: Move substitutions/witness tables deallocation to the outer context
Fixes a bug where substitutions and witness tables buffers are going to be deallocated at the end of the `if` block before calling `_executeDistributedTarget`.
1 parent 59ff689 commit 1fc0f3c

File tree

1 file changed

+5
-7
lines changed

1 file changed

+5
-7
lines changed

stdlib/public/Distributed/DistributedActorSystem.swift

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -179,6 +179,11 @@ extension DistributedActorSystem {
179179
var witnessTablesBuffer: UnsafeRawPointer? = nil
180180
var numWitnessTables: Int = 0
181181

182+
defer {
183+
substitutionsBuffer?.deallocate()
184+
witnessTablesBuffer?.deallocate()
185+
}
186+
182187
if let genericEnv = genericEnv {
183188
let subs = try invocationDecoder.decodeGenericSubstitutions()
184189

@@ -188,9 +193,6 @@ extension DistributedActorSystem {
188193
}
189194

190195
substitutionsBuffer = .allocate(capacity: subs.count)
191-
defer {
192-
substitutionsBuffer?.deallocate()
193-
}
194196

195197
for (offset, substitution) in subs.enumerated() {
196198
let element = substitutionsBuffer?.advanced(by: offset)
@@ -199,10 +201,6 @@ extension DistributedActorSystem {
199201

200202
(witnessTablesBuffer, numWitnessTables) = _getWitnessTablesFor(environment: genericEnv,
201203
genericArguments: substitutionsBuffer!)
202-
defer {
203-
witnessTablesBuffer?.deallocate()
204-
}
205-
206204
if numWitnessTables < 0 {
207205
throw ExecuteDistributedTargetError(
208206
message: "Generic substitutions \(subs) do not satisfy generic requirements of \(mangledTargetName)")

0 commit comments

Comments
 (0)