From 32303a9130def171462e39aad3b1b0ebe0ec0b1f Mon Sep 17 00:00:00 2001 From: Russ Butler Date: Mon, 2 Oct 2017 19:32:20 -0500 Subject: [PATCH] Fix sleep lock underflow in LowPowerTimer If a LowPowerTimer is started and then goes out of scope then a deep sleep lock underflow can occur. This is because the the variable '_lock_deepsleep' is checked when starting the timer but is not checked in the destructor, which unconditionally releases the deep sleep lock. --- drivers/Timer.cpp | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/drivers/Timer.cpp b/drivers/Timer.cpp index 5da9863d95..f523974e6b 100644 --- a/drivers/Timer.cpp +++ b/drivers/Timer.cpp @@ -35,7 +35,9 @@ Timer::Timer(const ticker_data_t *data) : _running(), _start(), _time(), _ticker Timer::~Timer() { core_util_critical_section_enter(); if (_running) { - sleep_manager_unlock_deep_sleep(); + if(_lock_deepsleep) { + sleep_manager_unlock_deep_sleep(); + } } _running = 0; core_util_critical_section_exit();