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 @@ -2874,11 +2874,22 @@ static bool _dynamicCastClassToValueViaObjCBridgeable(
2874
2874
swift_unknownRetain (srcObject);
2875
2875
}
2876
2876
2877
+ // The extra byte is for the tag.
2878
+ auto targetSize = targetType->getValueWitnesses ()->size + 1 ;
2879
+ auto targetAlignMask = targetType->getValueWitnesses ()->getAlignmentMask ();
2880
+
2877
2881
// Object that frees a buffer when it goes out of scope.
2878
2882
struct FreeBuffer {
2879
2883
void *Buffer = nullptr ;
2880
- ~FreeBuffer () { free (Buffer); }
2881
- } freeBuffer;
2884
+ size_t size, alignMask;
2885
+ FreeBuffer (size_t size, size_t alignMask) :
2886
+ size (size), alignMask(alignMask) {}
2887
+
2888
+ ~FreeBuffer () {
2889
+ if (Buffer)
2890
+ swift_slowDealloc (Buffer, size, alignMask);
2891
+ }
2892
+ } freeBuffer{targetSize, targetAlignMask};
2882
2893
2883
2894
// Allocate a buffer to store the T? returned by bridging.
2884
2895
// The extra byte is for the tag.
@@ -2890,7 +2901,7 @@ static bool _dynamicCastClassToValueViaObjCBridgeable(
2890
2901
optDestBuffer = inlineBuffer;
2891
2902
} else {
2892
2903
// Allocate a buffer.
2893
- optDestBuffer = malloc (targetType-> getValueWitnesses ()-> size );
2904
+ optDestBuffer = swift_slowAlloc (targetSize, targetAlignMask );
2894
2905
freeBuffer.Buffer = optDestBuffer;
2895
2906
}
2896
2907
You can’t perform that action at this time.
0 commit comments