Skip to content

Commit 3a7a408

Browse files
committed
rt: Free all outstanding boxes at task death
1 parent 106c9fa commit 3a7a408

File tree

3 files changed

+21
-0
lines changed

3 files changed

+21
-0
lines changed

mk/rt.mk

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,7 @@ RUNTIME_CS_$(1) := \
6767
rt/rust_abi.cpp \
6868
rt/rust_cc.cpp \
6969
rt/rust_debug.cpp \
70+
rt/rust_box_annihilator.cpp \
7071
rt/memory_region.cpp \
7172
rt/boxed_region.cpp \
7273
rt/arch/$$(HOST_$(1))/context.cpp

src/rt/rust_box_annihilator.cpp

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
#include "rust_internal.h"
2+
#include "rust_shape.h"
3+
4+
void
5+
annihilate_boxes(rust_task *task) {
6+
LOG(task, gc, "annihilating boxes for task %p", task);
7+
8+
boxed_region *boxed = &task->boxed;
9+
rust_opaque_box *box = boxed->first_live_alloc();
10+
while (box != NULL) {
11+
rust_opaque_box *tmp = box;
12+
box = box->next;
13+
boxed->free(tmp);
14+
}
15+
}

src/rt/rust_task.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,12 +87,17 @@ struct cleanup_args {
8787
bool threw_exception;
8888
};
8989

90+
void
91+
annihilate_boxes(rust_task *task);
92+
9093
void
9194
cleanup_task(cleanup_args *args) {
9295
spawn_args *a = args->spargs;
9396
bool threw_exception = args->threw_exception;
9497
rust_task *task = a->task;
9598

99+
cc::do_cc(task);
100+
annihilate_boxes(task);
96101
cc::do_final_cc(task);
97102

98103
task->die();

0 commit comments

Comments
 (0)