Skip to content

Commit 4b35609

Browse files
committed
Change the locking rules around channel disassociation again
This prevents port's destructor from accessing a deleted channel
1 parent 12ab651 commit 4b35609

File tree

2 files changed

+4
-1
lines changed

2 files changed

+4
-1
lines changed

src/rt/rust_chan.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,9 +51,9 @@ bool rust_chan::is_associated() {
5151
* Unlink this channel from its associated port.
5252
*/
5353
void rust_chan::disassociate() {
54+
// Precondition: port->referent()->lock must be held
5455
A(kernel, is_associated(),
5556
"Channel must be associated with a port.");
56-
scoped_lock with(port->referent()->lock);
5757
if (port->is_proxy() == false) {
5858
KLOG(kernel, task,
5959
"disassociating chan: 0x%" PRIxPTR " from port: 0x%" PRIxPTR,
@@ -127,6 +127,7 @@ void rust_chan::destroy() {
127127
// Here is a good place to delete the port proxy we allocated
128128
// in upcall_clone_chan.
129129
rust_proxy<rust_port> *proxy = port->as_proxy();
130+
scoped_lock with(port->referent()->lock);
130131
disassociate();
131132
delete proxy;
132133
} else {
@@ -143,6 +144,7 @@ void rust_chan::destroy() {
143144
if (buffer.is_empty() == false) {
144145
return;
145146
}
147+
scoped_lock with(port->referent()->lock);
146148
disassociate();
147149
}
148150
}

src/rt/rust_port.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ rust_port::~rust_port() {
2121

2222
// Disassociate channels from this port.
2323
while (chans.is_empty() == false) {
24+
scoped_lock with(referent()->lock);
2425
rust_chan *chan = chans.peek();
2526
chan->disassociate();
2627

0 commit comments

Comments
 (0)