Skip to content

Commit e66fd1a

Browse files
committed
[+0-all-args] When casting a value to NSError, release the value passed to _swift_stdlib_bridgeErrorToNSError since it is at +0 now.
rdar://34222540
1 parent f98fc84 commit e66fd1a

File tree

1 file changed

+5
-1
lines changed

1 file changed

+5
-1
lines changed

stdlib/public/runtime/Casting.cpp

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1973,7 +1973,11 @@ static id dynamicCastValueToNSError(OpaqueValue *src,
19731973

19741974
BoxPair errorBox = swift_allocError(srcType, srcErrorWitness, src,
19751975
/*isTake*/ flags & DynamicCastFlags::TakeOnSuccess);
1976-
return _swift_stdlib_bridgeErrorToNSError((SwiftError*)errorBox.object);
1976+
auto *error = (SwiftError *)errorBox.object;
1977+
id result = _swift_stdlib_bridgeErrorToNSError(error);
1978+
// Now that we have bridged the error to nserror, release the error.
1979+
SWIFT_CC_PLUSZERO_GUARD(swift_errorRelease(error));
1980+
return result;
19771981
}
19781982

19791983
#endif

0 commit comments

Comments
 (0)