mirror of
https://github.com/apple/swift.git
synced 2025-12-21 12:14:44 +01:00
SR-7732: Dynamic casting CFError to Error results in a memory leak (#28686)
* SR-7732: Dynamic casting CFError to Error results in a memory leak The special handling for casting CFError/NSError to Swift Error type was using cleanup code that didn't correctly handle this case. This replaces the cleanup code with a more targeted version. Fixes: SR-7732 Fixes: rdar://problem/40423061 * Whitespace fixes * Don't rely on localizable strings to verify test behavior. I've verified this simplified test still leaks with the original code and does not leak with the fixed code. * Don't test against old runtimes that predate this fix * Explicitly test both NSError and CFError
This commit is contained in:
@@ -911,7 +911,9 @@ static bool _dynamicCastToExistential(OpaqueValue *dest,
|
||||
srcDynamicType,
|
||||
errorWitness)) {
|
||||
*destBoxAddr = reinterpret_cast<SwiftError*>(embedded);
|
||||
maybeDeallocateSource(true);
|
||||
if (shouldDeallocateSource(true, flags)) {
|
||||
srcType->vw_destroy(src);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
#endif
|
||||
|
||||
Reference in New Issue
Block a user