diff --git a/cores/esp8266/Schedule.cpp b/cores/esp8266/Schedule.cpp index 5e56ac58df..ed39736e55 100644 --- a/cores/esp8266/Schedule.cpp +++ b/cores/esp8266/Schedule.cpp @@ -45,14 +45,9 @@ static scheduled_fn_t* get_fn_unsafe () // if no unused items, and count not too high, allocate a new one else if (sCount < SCHEDULED_FN_MAX_COUNT) { - // calling malloc instead of new to avoid exception raising while in ISR - // construct complex members in place (never raises exceptions) - result = (scheduled_fn_t*)malloc(sizeof(scheduled_fn_t)); + result = new (std::nothrow) scheduled_fn_t; if (result) - { - new (&result->mFunc) decltype(result->mFunc)(); ++sCount; - } } return result; } @@ -91,7 +86,7 @@ bool schedule_recurrent_function_us (const std::function& fn, uint32 esp8266::InterruptLock lockAllInterruptsInThisScope; - recurrent_fn_t* item = new recurrent_fn_t(repeat_us); + recurrent_fn_t* item = new (std::nothrow) recurrent_fn_t(repeat_us); if (!item) return false;