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:
tbkka
2019-12-12 12:30:21 -08:00
committed by GitHub
parent ee43a79dd0
commit cc8f8e929c
2 changed files with 33 additions and 4 deletions

View File

@@ -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