Cast void pointer before deallocating with delete[]

The stack memory is a `void*` which creates a warning when using
the `delete[]` operator because it is unable to call the destructor of
of an unknown object type.
pull/11696/head
Hugues Kamba 2019-09-02 15:15:14 +01:00 committed by adbridge
parent 6176f066f4
commit 639ee4b3b4
1 changed files with 4 additions and 2 deletions

View File

@ -113,7 +113,8 @@ osStatus Thread::start(mbed::Callback<void()> task)
_tid = osThreadNew(Thread::_thunk, this, &_attr); _tid = osThreadNew(Thread::_thunk, this, &_attr);
if (_tid == nullptr) { if (_tid == nullptr) {
if (_dynamic_stack) { if (_dynamic_stack) {
delete[] _attr.stack_mem; // Cast before deallocation as delete[] does not accept void*
delete[] static_cast<uint32_t *>(_attr.stack_mem);
_attr.stack_mem = nullptr; _attr.stack_mem = nullptr;
} }
_mutex.unlock(); _mutex.unlock();
@ -417,7 +418,8 @@ Thread::~Thread()
// terminate is thread safe // terminate is thread safe
terminate(); terminate();
if (_dynamic_stack) { if (_dynamic_stack) {
delete[] _attr.stack_mem; // Cast before deallocation as delete[] does not accept void*
delete[] static_cast<uint32_t *>(_attr.stack_mem);
_attr.stack_mem = nullptr; _attr.stack_mem = nullptr;
} }
} }