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/11393/head
Hugues Kamba 2019-09-02 15:15:14 +01:00
parent bdd6cb8dee
commit a562841992
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);
if (_tid == nullptr) {
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;
}
_mutex.unlock();
@ -417,7 +418,8 @@ Thread::~Thread()
// terminate is thread safe
terminate();
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;
}
}