Skip to content

Commit 49c982d

Browse files
committed
bugfix #144: Do not free kstack when the main thread exits
1 parent 1046976 commit 49c982d

File tree

1 file changed

+7
-2
lines changed

1 file changed

+7
-2
lines changed

os/src/task/mod.rs

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -131,8 +131,13 @@ pub fn exit_current_and_run_next(exit_code: i32) {
131131
process_inner.memory_set.recycle_data_pages();
132132
// drop file descriptors
133133
process_inner.fd_table.clear();
134-
// remove all tasks
135-
process_inner.tasks.clear();
134+
// Remove all tasks except for the main thread itself.
135+
// This is because we are still using the kstack under the TCB
136+
// of the main thread. This TCB, including its kstack, will be
137+
// deallocated when the process is reaped via waitpid.
138+
while process_inner.tasks.len() > 1 {
139+
process_inner.tasks.pop();
140+
}
136141
}
137142
drop(process);
138143
// we do not have to save task context

0 commit comments

Comments
 (0)