diff --git a/components/checker/checkercomponent.cpp b/components/checker/checkercomponent.cpp index 3c731f34a..12b3bad69 100644 --- a/components/checker/checkercomponent.cpp +++ b/components/checker/checkercomponent.cpp @@ -63,7 +63,12 @@ void CheckerComponent::CheckTimerHandler(void) CheckTimeView& idx = boost::get<1>(m_IdleServices); CheckTimeView::iterator it = idx.begin(); - Service::Ptr service = *it; + Service::Ptr service = it->lock(); + + if (!service) { + idx.erase(it); + continue; + } if (service->GetNextCheck() > now) break; @@ -206,8 +211,19 @@ void CheckerComponent::RescheduleCheckTimer(void) typedef nth_index::type CheckTimeView; CheckTimeView& idx = boost::get<1>(m_IdleServices); - CheckTimeView::iterator it = idx.begin(); - Service::Ptr service = *it; + Service::Ptr service; + + do { + CheckTimeView::iterator it = idx.begin(); + + if (it == idx.end()) + return; + + service = it->lock(); + + if (!service) + idx.erase(it); + } while (!service); m_CheckTimer->Reschedule(service->GetNextCheck()); } diff --git a/components/checker/checkercomponent.h b/components/checker/checkercomponent.h index a6f652779..f930fa04b 100644 --- a/components/checker/checkercomponent.h +++ b/components/checker/checkercomponent.h @@ -30,8 +30,13 @@ struct ServiceNextCheckExtractor { typedef double result_type; - double operator()(const Service::Ptr& service) + double operator()(const Service::WeakPtr& wservice) { + Service::Ptr service = wservice.lock(); + + if (!service) + return 0; + return service->GetNextCheck(); } }; @@ -46,9 +51,9 @@ public: typedef weak_ptr WeakPtr; typedef multi_index_container< - Service::Ptr, + Service::WeakPtr, indexed_by< - ordered_unique >, + ordered_unique >, ordered_non_unique > > ServiceSet;