Fix potential memory leak

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

View file

@ -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);