File tree 1 file changed +12
-6
lines changed
1 file changed +12
-6
lines changed Original file line number Diff line number Diff line change @@ -1592,12 +1592,18 @@ static bool _dynamicCastFromExistential(OpaqueValue *dest,
1592
1592
1593
1593
bool result = swift_dynamicCast (dest, srcValue, srcCapturedType,
1594
1594
targetType, subFlags);
1595
- // Deallocate the existential husk if we took from it.
1596
- if (canTake && result && isOutOfLine)
1597
- _maybeDeallocateOpaqueExistential (src, result, flags);
1598
- // If we couldn't take, we still may need to destroy the whole value.
1599
- else if (!canTake && shouldDeallocateSource (result, flags))
1600
- srcType->vw_destroy (src);
1595
+
1596
+ if (!canTake) {
1597
+ // swift_dynamicCast performed no memory management.
1598
+ // Destroy the value if requested.
1599
+ if (shouldDeallocateSource (result, flags))
1600
+ srcType->vw_destroy (src);
1601
+ } else {
1602
+ // swift_dynamicCast took or destroyed the value as per the original request
1603
+ // We may still have an opaque existential container to deallocate.
1604
+ if (isOutOfLine)
1605
+ _maybeDeallocateOpaqueExistential (src, result, flags);
1606
+ }
1601
1607
1602
1608
return result;
1603
1609
}
You can’t perform that action at this time.
0 commit comments