Skip to content

Commit d27f157

Browse files
committed
bugfix #144: Do not free kstack when the main thread exits
1 parent c431dac commit d27f157

File tree

1 file changed

+7
-0
lines changed

1 file changed

+7
-0
lines changed

os/src/task/mod.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,13 @@ pub fn exit_current_and_run_next(exit_code: i32) {
127127
process_inner.memory_set.recycle_data_pages();
128128
// drop file descriptors
129129
process_inner.fd_table.clear();
130+
// Remove all tasks except for the main thread itself.
131+
// This is because we are still using the kstack under the TCB
132+
// of the main thread. This TCB, including its kstack, will be
133+
// deallocated when the process is reaped via waitpid.
134+
while process_inner.tasks.len() > 1 {
135+
process_inner.tasks.pop();
136+
}
130137
}
131138
drop(process);
132139
// we do not have to save task context

0 commit comments

Comments
 (0)