Skip to content

Commit c1ed83e

Browse files
committed
Fix use-after-free through diagnostic argument
1 parent 1f28a04 commit c1ed83e

File tree

1 file changed

+11
-8
lines changed

1 file changed

+11
-8
lines changed

lib/Sema/TypeCheckProtocol.cpp

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5002,16 +5002,19 @@ static void diagnoseConformanceIsolationErrors(
50025002
if (potentialIsolation && potentialIsolation->isGlobalActor() &&
50035003
!conformance->isIsolated()) {
50045004
bool isMainActor = false;
5005-
Type globalActorIsolation = potentialIsolation->getGlobalActor();
5006-
if (auto nominal = globalActorIsolation->getAnyNominal())
5005+
Type globalActorType = potentialIsolation->getGlobalActor();
5006+
if (auto nominal = globalActorType->getAnyNominal())
50075007
isMainActor = nominal->isMainActor();
50085008

5009-
auto diag = ctx.Diags.diagnose(
5010-
conformance->getProtocolNameLoc(),
5011-
diag::note_isolate_conformance_to_global_actor, globalActorIsolation,
5012-
isMainActor, globalActorIsolation.getString());
5013-
conformance->applyConformanceAttribute(
5014-
diag, "@" + globalActorIsolation.getString());
5009+
// Take permanent ownership of the string. The diagnostic may outlive this
5010+
// function call.
5011+
auto globalActorTypeStr = ctx.AllocateCopy(globalActorType.getString());
5012+
auto diag =
5013+
ctx.Diags.diagnose(conformance->getProtocolNameLoc(),
5014+
diag::note_isolate_conformance_to_global_actor,
5015+
globalActorType, isMainActor, globalActorTypeStr);
5016+
conformance->applyConformanceAttribute(diag,
5017+
"@" + globalActorTypeStr.str());
50155018
}
50165019

50175020
// If marking witnesses as 'nonisolated' could work, suggest that.

0 commit comments

Comments
 (0)