Skip to content

Commit 58ab8f8

Browse files
committed
[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
1 parent 314cf64 commit 58ab8f8

File tree

1 file changed

+3
-0
lines changed

1 file changed

+3
-0
lines changed

stdlib/public/runtime/Casting.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1922,6 +1922,9 @@ static bool tryDynamicCastBoxedSwiftValue(OpaqueValue *dest,
19221922

19231923
#if !SWIFT_OBJC_INTEROP // __SwiftValue is a native class:
19241924
if (swift_unboxFromSwiftValueWithType(src, dest, targetType)) {
1925+
// Release the source if we need to.
1926+
if (flags & DynamicCastFlags::TakeOnSuccess)
1927+
srcType->vw_destroy(src);
19251928
return true;
19261929
}
19271930
#endif

0 commit comments

Comments
 (0)