Skip to content

Commit 3f35506

Browse files
d-a-vdevyte
authored andcommitted
using std::nothrow instead of malloc (#6251)
1 parent 6272e89 commit 3f35506

File tree

1 file changed

+2
-7
lines changed

1 file changed

+2
-7
lines changed

cores/esp8266/Schedule.cpp

+2-7
Original file line numberDiff line numberDiff line change
@@ -45,14 +45,9 @@ static scheduled_fn_t* get_fn_unsafe ()
4545
// if no unused items, and count not too high, allocate a new one
4646
else if (sCount < SCHEDULED_FN_MAX_COUNT)
4747
{
48-
// calling malloc instead of new to avoid exception raising while in ISR
49-
// construct complex members in place (never raises exceptions)
50-
result = (scheduled_fn_t*)malloc(sizeof(scheduled_fn_t));
48+
result = new (std::nothrow) scheduled_fn_t;
5149
if (result)
52-
{
53-
new (&result->mFunc) decltype(result->mFunc)();
5450
++sCount;
55-
}
5651
}
5752
return result;
5853
}
@@ -91,7 +86,7 @@ bool schedule_recurrent_function_us (const std::function<bool(void)>& fn, uint32
9186

9287
esp8266::InterruptLock lockAllInterruptsInThisScope;
9388

94-
recurrent_fn_t* item = new recurrent_fn_t(repeat_us);
89+
recurrent_fn_t* item = new (std::nothrow) recurrent_fn_t(repeat_us);
9590
if (!item)
9691
return false;
9792

0 commit comments

Comments
 (0)