Skip to content

Commit 01b1043

Browse files
committed
Fix a memory issue with actors in the runtime system, by @phausler
1 parent 93f017b commit 01b1043

File tree

1 file changed

+12
-0
lines changed

1 file changed

+12
-0
lines changed

stdlib/public/Concurrency/Actor.cpp

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1094,8 +1094,15 @@ Job *DefaultActorImpl::claimNextJobOrGiveUp(bool actorIsOwned,
10941094
/// the current thread, and keep processing whatever actor we're
10951095
/// running when code returns back to us until we're not processing
10961096
/// any actors anymore.
1097+
///
1098+
/// \param currentActor is expected to be passed in as retained to ensure that
1099+
/// the actor lives for the duration of job execution.
1100+
/// Note that this may conflict with the retain/release
1101+
/// design in the DefaultActorImpl, but it does fix bugs!
10971102
static void processDefaultActor(DefaultActorImpl *currentActor,
10981103
RunningJobInfo runner) {
1104+
DefaultActorImpl *actor = currentActor;
1105+
10991106
// Register that we're processing a default actor in this frame.
11001107
ExecutorTrackingInfo trackingInfo;
11011108
auto activeTrackingInfo = trackingInfo.enterOrUpdate(
@@ -1142,6 +1149,8 @@ static void processDefaultActor(DefaultActorImpl *currentActor,
11421149
// If we still have an active actor, we should give it up.
11431150
if (currentActor)
11441151
currentActor->giveUpThread(runner);
1152+
1153+
swift_release(actor);
11451154
}
11461155

11471156
void ProcessInlineJob::process(Job *job, ExecutorRef _executor) {
@@ -1153,6 +1162,7 @@ void ProcessInlineJob::process(Job *job, ExecutorRef _executor) {
11531162
auto runner = RunningJobInfo::forInline(targetPriority);
11541163

11551164
// FIXME: force tail call
1165+
swift_retain(actor);
11561166
return processDefaultActor(actor, runner);
11571167
}
11581168

@@ -1168,6 +1178,7 @@ void ProcessOutOfLineJob::process(Job *job, ExecutorRef _executor) {
11681178
delete self;
11691179

11701180
// FIXME: force tail call
1181+
swift_retain(actor);
11711182
return processDefaultActor(actor, runner);
11721183
}
11731184

@@ -1179,6 +1190,7 @@ void ProcessOverrideJob::process(Job *job, ExecutorRef _executor) {
11791190
auto runner = RunningJobInfo::forOverride(self);
11801191

11811192
// FIXME: force tail call
1193+
swift_retain(actor);
11821194
return processDefaultActor(actor, runner);
11831195
}
11841196

0 commit comments

Comments
 (0)