diff --git a/rtos/source/Thread.cpp b/rtos/source/Thread.cpp index 0d43391e49..94f1fdb366 100644 --- a/rtos/source/Thread.cpp +++ b/rtos/source/Thread.cpp @@ -113,7 +113,8 @@ osStatus Thread::start(mbed::Callback 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(_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(_attr.stack_mem); _attr.stack_mem = nullptr; } }