Fix potential memory leak
Some checks reported errors
continuous-integration/drone/push Build was killed
continuous-integration/drone/pr Build was killed

This commit is contained in:
Alex 2022-09-13 12:34:03 +02:00
parent b509e6057f
commit 395f942fc7
Signed by: lx
GPG key ID: 0E496D15096376BE

View file

@ -118,6 +118,9 @@ impl SendQueuePriority {
let order_vec = self.order.get_mut(&stream).unwrap(); let order_vec = self.order.get_mut(&stream).unwrap();
let j = order_vec.iter().position(|x| *x == order).unwrap(); let j = order_vec.iter().position(|x| *x == order).unwrap();
order_vec.remove(j).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(); item.sent += data_frame.data().len();
if eos || is_err { 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 { if let Some(OrderTag(stream, order)) = item.order_tag {
assert_eq!( let order_stream = self.order.get_mut(&stream).unwrap();
self.order.get_mut(&stream).unwrap().pop_front(), assert_eq!(order_stream.pop_front(), Some(order));
Some(order) if order_stream.is_empty() {
) self.order.remove(&stream);
} }
}
// Remove item from sending queue
self.items.remove(j); self.items.remove(j);
} else { } else {
// Move item later in send queue to implement LAS scheduling
// (LAS = Least Attained Service)
for k in j..self.items.len() - 1 { for k in j..self.items.len() - 1 {
if self.items[k].sent >= self.items[k + 1].sent { if self.items[k].sent >= self.items[k + 1].sent {
self.items.swap(k, k + 1); self.items.swap(k, k + 1);