File tree Expand file tree Collapse file tree 1 file changed +14
-3
lines changed Expand file tree Collapse file tree 1 file changed +14
-3
lines changed Original file line number Diff line number Diff line change @@ -2675,11 +2675,22 @@ static bool _dynamicCastClassToValueViaObjCBridgeable(
2675
2675
swift_unknownRetain (srcObject);
2676
2676
}
2677
2677
2678
+ // The extra byte is for the tag.
2679
+ auto targetSize = targetType->getValueWitnesses ()->size + 1 ;
2680
+ auto targetAlignMask = targetType->getValueWitnesses ()->getAlignmentMask ();
2681
+
2678
2682
// Object that frees a buffer when it goes out of scope.
2679
2683
struct FreeBuffer {
2680
2684
void *Buffer = nullptr ;
2681
- ~FreeBuffer () { free (Buffer); }
2682
- } freeBuffer;
2685
+ size_t size, alignMask;
2686
+ FreeBuffer (size_t size, size_t alignMask) :
2687
+ size (size), alignMask(alignMask) {}
2688
+
2689
+ ~FreeBuffer () {
2690
+ if (Buffer)
2691
+ swift_slowDealloc (Buffer, size, alignMask);
2692
+ }
2693
+ } freeBuffer{targetSize, targetAlignMask};
2683
2694
2684
2695
// Allocate a buffer to store the T? returned by bridging.
2685
2696
// The extra byte is for the tag.
@@ -2691,7 +2702,7 @@ static bool _dynamicCastClassToValueViaObjCBridgeable(
2691
2702
optDestBuffer = inlineBuffer;
2692
2703
} else {
2693
2704
// Allocate a buffer.
2694
- optDestBuffer = malloc (targetType-> getValueWitnesses ()-> size );
2705
+ optDestBuffer = swift_slowAlloc (targetSize, targetAlignMask );
2695
2706
freeBuffer.Buffer = optDestBuffer;
2696
2707
}
2697
2708
You can’t perform that action at this time.
0 commit comments