Skip to content

Commit be769c0

Browse files
authored
Merge pull request #11393 from hugueskamba/hk-fix-thread-stack-mem-deallocation
Cast void pointer before deallocating with delete[]
2 parents 7b06ce5 + a562841 commit be769c0

File tree

1 file changed

+4
-2
lines changed

1 file changed

+4
-2
lines changed

rtos/source/Thread.cpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,8 @@ osStatus Thread::start(mbed::Callback<void()> task)
113113
_tid = osThreadNew(Thread::_thunk, this, &_attr);
114114
if (_tid == nullptr) {
115115
if (_dynamic_stack) {
116-
delete[] _attr.stack_mem;
116+
// Cast before deallocation as delete[] does not accept void*
117+
delete[] static_cast<uint32_t *>(_attr.stack_mem);
117118
_attr.stack_mem = nullptr;
118119
}
119120
_mutex.unlock();
@@ -417,7 +418,8 @@ Thread::~Thread()
417418
// terminate is thread safe
418419
terminate();
419420
if (_dynamic_stack) {
420-
delete[] _attr.stack_mem;
421+
// Cast before deallocation as delete[] does not accept void*
422+
delete[] static_cast<uint32_t *>(_attr.stack_mem);
421423
_attr.stack_mem = nullptr;
422424
}
423425
}

0 commit comments

Comments
 (0)