sync: free chan Blocks when Chan is dropped (#978)

This commit is contained in:
Sean McArthur
2019-03-13 10:38:14 -07:00
committed by Carl Lerche
parent a1871b1480
commit 27148d6110
3 changed files with 35 additions and 7 deletions
+3
View File
@@ -326,10 +326,13 @@ impl<T, S> Drop for Chan<T, S> {
fn drop(&mut self) {
use super::block::Read::Value;
// Safety: the only owner of the rx fields is Chan, and eing
// inside its own Drop means we're the last ones to touch it.
self.rx_fields.with_mut(|rx_fields_ptr| {
let rx_fields = unsafe { &mut *rx_fields_ptr };
while let Some(Value(_)) = rx_fields.list.pop(&self.tx) {}
unsafe { rx_fields.list.free_blocks() };
});
}
}