mirror of
https://github.com/esp8266/Arduino.git
synced 2025-06-07 16:23:38 +03:00
scheduled function: replacing new by malloc needs to initialize complex members (#6233)
* scheduled function: replacing new by malloc needs to initialize complex members Functional was not initialized because of malloc() instead of new. First assignment calls destructor on initial value which was not constructed (->frozen,wdt).
This commit is contained in:
parent
909a9c4f4c
commit
b94ea923b0
@ -41,14 +41,18 @@ static scheduled_fn_t* get_fn_unsafe ()
|
|||||||
{
|
{
|
||||||
result = sUnused;
|
result = sUnused;
|
||||||
sUnused = sUnused->mNext;
|
sUnused = sUnused->mNext;
|
||||||
result->mNext = nullptr;
|
|
||||||
}
|
}
|
||||||
// if no unused items, and count not too high, allocate a new one
|
// if no unused items, and count not too high, allocate a new one
|
||||||
else if (sCount < SCHEDULED_FN_MAX_COUNT)
|
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 = (scheduled_fn_t*)malloc(sizeof(scheduled_fn_t));
|
||||||
if (result)
|
if (result)
|
||||||
|
{
|
||||||
|
new (&result->mFunc) decltype(result->mFunc)();
|
||||||
++sCount;
|
++sCount;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
@ -70,6 +74,7 @@ bool schedule_function (const std::function<void(void)>& fn)
|
|||||||
return false;
|
return false;
|
||||||
|
|
||||||
item->mFunc = fn;
|
item->mFunc = fn;
|
||||||
|
item->mNext = nullptr;
|
||||||
|
|
||||||
if (sFirst)
|
if (sFirst)
|
||||||
sLast->mNext = item;
|
sLast->mNext = item;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user