[Runtime] Fix leak in tryDynamicCastBoxedSwiftValue.

The call to swift_unboxFromSwiftValueWithType needs to destroy the value on success when requested in the flags.

rdar://problem/44686587
This commit is contained in:
Mike Ash
2018-11-29 12:59:44 -05:00
parent 331f0d2394
commit f1f83968d6

View File

@@ -1922,6 +1922,9 @@ static bool tryDynamicCastBoxedSwiftValue(OpaqueValue *dest,
#if !SWIFT_OBJC_INTEROP // __SwiftValue is a native class:
if (swift_unboxFromSwiftValueWithType(src, dest, targetType)) {
// Release the source if we need to.
if (flags & DynamicCastFlags::TakeOnSuccess)
srcType->vw_destroy(src);
return true;
}
#endif