Skip to content
Snippets Groups Projects
Commit 5574e5f6 authored by Adrien Béraud's avatar Adrien Béraud
Browse files

scheduled_executor: prevent use-after-free in reschedule

Change-Id: Id9fe8099cc0e82845e2a2d1cb4c4128f281ba982
parent fa7fb8be
No related branches found
No related tags found
No related merge requests found
...@@ -54,24 +54,20 @@ ScheduledExecutor::~ScheduledExecutor() ...@@ -54,24 +54,20 @@ ScheduledExecutor::~ScheduledExecutor()
void void
ScheduledExecutor::stop() ScheduledExecutor::stop()
{
{ {
std::lock_guard<std::mutex> lock(jobLock_); std::lock_guard<std::mutex> lock(jobLock_);
*running_ = false; *running_ = false;
jobs_.clear(); jobs_.clear();
}
cv_.notify_all(); cv_.notify_all();
} }
void void
ScheduledExecutor::run(std::function<void()>&& job, ScheduledExecutor::run(std::function<void()>&& job,
const char* filename, uint32_t linum) const char* filename, uint32_t linum)
{
{ {
std::lock_guard<std::mutex> lock(jobLock_); std::lock_guard<std::mutex> lock(jobLock_);
auto now = clock::now(); auto now = clock::now();
jobs_[now].emplace_back(std::move(job), filename, linum); jobs_[now].emplace_back(std::move(job), filename, linum);
}
cv_.notify_all(); cv_.notify_all();
} }
...@@ -115,11 +111,11 @@ ScheduledExecutor::reschedule(std::shared_ptr<RepeatedTask> task, time_point t, ...@@ -115,11 +111,11 @@ ScheduledExecutor::reschedule(std::shared_ptr<RepeatedTask> task, time_point t,
void void
ScheduledExecutor::schedule(std::shared_ptr<Task> task, time_point t) ScheduledExecutor::schedule(std::shared_ptr<Task> task, time_point t)
{ {
{ const char* filename = task->job().filename;
uint32_t linenum = task->job().linum;
std::lock_guard<std::mutex> lock(jobLock_); std::lock_guard<std::mutex> lock(jobLock_);
jobs_[t].emplace_back([task = std::move(task), this] { task->run(name_.c_str()); }, jobs_[t].emplace_back([task = std::move(task), this] { task->run(name_.c_str()); },
task->job().filename, task->job().linum); filename, linenum);
}
cv_.notify_all(); cv_.notify_all();
} }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment