Skip to content

Commit cfd70d7

Browse files
authored
Merge pull request #85204 from mikeash/tasklocal-no-task-free-fix
[Concurrency] Fix MarkerItem::create to use malloc when there's no task.
2 parents 048c927 + 29245e4 commit cfd70d7

File tree

1 file changed

+6
-1
lines changed

1 file changed

+6
-1
lines changed

stdlib/public/Concurrency/TaskLocal.cpp

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -250,7 +250,12 @@ void TaskLocal::Storage::initializeLinkParent(AsyncTask* task,
250250
TaskLocal::MarkerItem *TaskLocal::MarkerItem::create(AsyncTask *task,
251251
Item *next, Kind kind) {
252252
size_t amountToAllocate = sizeof(MarkerItem);
253-
void *allocation = _swift_task_alloc_specific(task, amountToAllocate);
253+
void *allocation;
254+
255+
// If we have a task, allocate from that task. If not, use malloc. This must
256+
// mirror the corresponding dealloc/free call in Item::destroy.
257+
if (task) allocation = _swift_task_alloc_specific(task, amountToAllocate);
258+
else allocation = malloc(amountToAllocate);
254259
return new (allocation) MarkerItem(next, kind);
255260
}
256261

0 commit comments

Comments
 (0)