@@ -531,7 +531,7 @@ extension DistributedActorSystem {
531
531
}
532
532
533
533
// Decode the return type
534
- func allocateReturnTypeBuffer < R> ( _: R . Type ) -> UnsafeMutableRawPointer ? {
534
+ func doAllocateReturnTypeBuffer < R> ( _: R . Type ) -> UnsafeMutableRawPointer ? {
535
535
return UnsafeMutableRawPointer ( UnsafeMutablePointer< R> . allocate( capacity: 1 ) )
536
536
}
537
537
@@ -549,15 +549,18 @@ extension DistributedActorSystem {
549
549
errorCode: . typeDeserializationFailure)
550
550
}
551
551
552
- guard let resultBuffer = _openExistential ( returnTypeFromTypeInfo, do: allocateReturnTypeBuffer ) else {
552
+ guard let resultBuffer = _openExistential ( returnTypeFromTypeInfo, do: doAllocateReturnTypeBuffer ) else {
553
553
throw ExecuteDistributedTargetError (
554
554
message: " Failed to allocate buffer for distributed target return type " ,
555
555
errorCode: . typeDeserializationFailure)
556
556
}
557
557
558
+ var executeDistributedTargetHasThrown = false
558
559
func doDestroyReturnTypeBuffer< R> ( _: R . Type ) {
559
560
let buf = resultBuffer. assumingMemoryBound ( to: R . self)
560
- buf. deinitialize ( count: 1 )
561
+ if !executeDistributedTargetHasThrown {
562
+ buf. deinitialize ( count: 1 )
563
+ }
561
564
buf. deallocate ( )
562
565
}
563
566
@@ -592,6 +595,7 @@ extension DistributedActorSystem {
592
595
)
593
596
}
594
597
} catch {
598
+ executeDistributedTargetHasThrown = true
595
599
try await handler. onThrow ( error: error)
596
600
}
597
601
}
0 commit comments