diff --git a/cores/esp8266/Schedule.cpp b/cores/esp8266/Schedule.cpp index 6fabd942a..27b973195 100644 --- a/cores/esp8266/Schedule.cpp +++ b/cores/esp8266/Schedule.cpp @@ -65,12 +65,12 @@ bool schedule_function(std::function fn) void run_scheduled_functions() { - while (sFirst) { - scheduled_fn_t* item = sFirst; - sFirst = item->mNext; - if (sFirst == NULL) { - sLast = NULL; - } + scheduled_fn_t* rFirst = sFirst; + sFirst = NULL; + sLast = NULL; + while (rFirst) { + scheduled_fn_t* item = rFirst; + rFirst = item->mNext; item->mFunc(); item->mFunc = std::function(); recycle_fn(item);