diff options
author | Alex Auvolat <alex@adnab.me> | 2022-09-13 12:34:03 +0200 |
---|---|---|
committer | Alex Auvolat <alex@adnab.me> | 2022-09-13 12:37:55 +0200 |
commit | 395f942fc745f5947005cad3a0e2ac15403fdbc9 (patch) | |
tree | b25491273f7a7218aa601f2e0dc5d6ee1adaaee8 /src/send.rs | |
parent | b509e6057f850971e3339404cfd2240193871402 (diff) | |
download | netapp-395f942fc745f5947005cad3a0e2ac15403fdbc9.tar.gz netapp-395f942fc745f5947005cad3a0e2ac15403fdbc9.zip |
Fix potential memory leak
Diffstat (limited to 'src/send.rs')
-rw-r--r-- | src/send.rs | 16 |
1 files changed, 12 insertions, 4 deletions
diff --git a/src/send.rs b/src/send.rs index 4e16179..0db0ba7 100644 --- a/src/send.rs +++ b/src/send.rs @@ -118,6 +118,9 @@ impl SendQueuePriority { let order_vec = self.order.get_mut(&stream).unwrap(); let j = order_vec.iter().position(|x| *x == order).unwrap(); order_vec.remove(j).unwrap(); + if order_vec.is_empty() { + self.order.remove(&stream); + } } } } @@ -147,14 +150,19 @@ impl SendQueuePriority { item.sent += data_frame.data().len(); if eos || is_err { + // If item had an order tag, remove it from the corresponding ordering list if let Some(OrderTag(stream, order)) = item.order_tag { - assert_eq!( - self.order.get_mut(&stream).unwrap().pop_front(), - Some(order) - ) + let order_stream = self.order.get_mut(&stream).unwrap(); + assert_eq!(order_stream.pop_front(), Some(order)); + if order_stream.is_empty() { + self.order.remove(&stream); + } } + // Remove item from sending queue self.items.remove(j); } else { + // Move item later in send queue to implement LAS scheduling + // (LAS = Least Attained Service) for k in j..self.items.len() - 1 { if self.items[k].sent >= self.items[k + 1].sent { self.items.swap(k, k + 1); |