Skip to content

Commit 8e250f3

Browse files
committed
Fix use-after-free through diagnostic argument
1 parent ad8c522 commit 8e250f3

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
@@ -5022,16 +5022,19 @@ static void diagnoseConformanceIsolationErrors(
50225022
if (potentialIsolation && potentialIsolation->isGlobalActor() &&
50235023
!conformance->isIsolated()) {
50245024
bool isMainActor = false;
5025-
Type globalActorIsolation = potentialIsolation->getGlobalActor();
5026-
if (auto nominal = globalActorIsolation->getAnyNominal())
5025+
Type globalActorType = potentialIsolation->getGlobalActor();
5026+
if (auto nominal = globalActorType->getAnyNominal())
50275027
isMainActor = nominal->isMainActor();
50285028

5029-
auto diag = ctx.Diags.diagnose(
5030-
conformance->getProtocolNameLoc(),
5031-
diag::note_isolate_conformance_to_global_actor, globalActorIsolation,
5032-
isMainActor, globalActorIsolation.getString());
5033-
conformance->applyConformanceAttribute(
5034-
diag, "@" + globalActorIsolation.getString());
5029+
// Take permanent ownership of the string. The diagnostic may outlive this
5030+
// function call.
5031+
auto globalActorTypeStr = ctx.AllocateCopy(globalActorType.getString());
5032+
auto diag =
5033+
ctx.Diags.diagnose(conformance->getProtocolNameLoc(),
5034+
diag::note_isolate_conformance_to_global_actor,
5035+
globalActorType, isMainActor, globalActorTypeStr);
5036+
conformance->applyConformanceAttribute(diag,
5037+
"@" + globalActorTypeStr.str());
50355038
}
50365039

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

0 commit comments

Comments
 (0)