Skip to content

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

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jul 4, 2019
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 2 additions & 7 deletions cores/esp8266/Schedule.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down Expand Up @@ -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;

Expand Down