mirror of
https://github.com/asterinas/asterinas.git
synced 2025-06-26 10:53:25 +00:00
Check the length of timers before delete
This commit is contained in:
committed by
Tate, Hongliang Tian
parent
c38907374a
commit
95aaef9aa1
@ -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();
|
||||
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);
|
||||
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
|
||||
}
|
||||
timer
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user