@@ -555,12 +555,20 @@ extension DistributedActorSystem {
555
555
errorCode: . typeDeserializationFailure)
556
556
}
557
557
558
- var executeDistributedTargetHasThrown = false
558
+ // we start out assuming we may have thrown,
559
+ // and set this to false when we return without having thrown
560
+ var executeDistributedTargetHasThrown = true
561
+
559
562
func doDestroyReturnTypeBuffer< R> ( _: R . Type ) {
560
563
let buf = resultBuffer. assumingMemoryBound ( to: R . self)
564
+
561
565
if !executeDistributedTargetHasThrown {
566
+ // since the _execute function has NOT thrown,
567
+ // there must be a value in the result buffer that we must deinitialize
562
568
buf. deinitialize ( count: 1 )
563
- }
569
+ } // otherwise, the _execute has thrown and not populated the result buffer
570
+
571
+ // finally, deallocate the buffer
564
572
buf. deallocate ( )
565
573
}
566
574
@@ -584,6 +592,9 @@ extension DistributedActorSystem {
584
592
witnessTables: witnessTablesBuffer,
585
593
numWitnessTables: UInt ( numWitnessTables)
586
594
)
595
+ // execute has not thrown, so the result buffer has been filled with some value,
596
+ // we must properly deinitialize it.
597
+ executeDistributedTargetHasThrown = false
587
598
588
599
if returnType == Void . self {
589
600
try await handler. onReturnVoid ( )
@@ -595,7 +606,6 @@ extension DistributedActorSystem {
595
606
)
596
607
}
597
608
} catch {
598
- executeDistributedTargetHasThrown = true
599
609
try await handler. onThrow ( error: error)
600
610
}
601
611
}
0 commit comments