Check the length of timers before delete

This commit is contained in:
Marsman1996
2024-08-21 15:13:29 +08:00
committed by Tate, Hongliang Tian
parent c38907374a
commit 95aaef9aa1

View File

@ -198,11 +198,15 @@ impl PosixTimerManager {
/// Removes the POSIX timer with the ID `timer_id`.
pub fn remove_posix_timer(&self, timer_id: usize) -> Option<Arc<Timer>> {
let mut timers = self.posix_timers.lock();
if timer_id < timers.len() {
let timer = timers[timer_id].take();
if timer.is_some() {
// Holding the lock of `posix_timers` is required to operate the `id_allocator`.
self.id_allocator.lock().free(timer_id);
}
timer
} else {
None
}
}
}