1
0
mirror of https://github.com/esp8266/Arduino.git synced 2025-06-06 05:21:22 +03:00

using std::nothrow instead of malloc (#6251)

This commit is contained in:
david gauchard 2019-07-04 03:59:54 +02:00 committed by Develo
parent 6272e897ca
commit 3f35506684

View File

@ -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<bool(void)>& 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;