Skip to content

Commit 75fa43e

Browse files
authored
[Concurrency] Clear current task TSD before enqueuing task in swift_task_switch. (swiftlang#74736)
The executor may execute and free the task while the enqueue code is still finishing up. If that code tries to get an async backtrace (for example, if it calls malloc/free with malloc stack logging enabled) then it will find a dangling pointer in the current task TSD, and dereferencing it may crash. rdar://130125017
1 parent c19c73d commit 75fa43e

File tree

1 file changed

+1
-1
lines changed

1 file changed

+1
-1
lines changed

stdlib/public/Concurrency/Actor.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2199,8 +2199,8 @@ static void swift_task_switchImpl(SWIFT_ASYNC_CONTEXT AsyncContext *resumeContex
21992199
"switch failed, task %p enqueued on executor %p (task executor: %p)",
22002200
task, newExecutor.getIdentity(), currentTaskExecutor.getIdentity());
22012201

2202-
task->flagAsAndEnqueueOnExecutor(newExecutor);
22032202
_swift_task_clearCurrent();
2203+
task->flagAsAndEnqueueOnExecutor(newExecutor);
22042204
}
22052205

22062206
/*****************************************************************************/

0 commit comments

Comments
 (0)