Skip to content

Commit d25dc43

Browse files
committed
Deallocate stack memory with free instead of 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 unkown object type.
1 parent bdd6cb8 commit d25dc43

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed

rtos/source/Thread.cpp

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@
1919
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
2020
* SOFTWARE.
2121
*/
22+
23+
#include <stdlib.h>
2224
#include "rtos/Thread.h"
2325
#include "rtos/ThisThread.h"
2426
#include "rtos_idle.h"
@@ -113,7 +115,8 @@ osStatus Thread::start(mbed::Callback<void()> task)
113115
_tid = osThreadNew(Thread::_thunk, this, &_attr);
114116
if (_tid == nullptr) {
115117
if (_dynamic_stack) {
116-
delete[] _attr.stack_mem;
118+
// Cast before deallocation as delete[] does not accept void*
119+
delete[] static_cast<uint32_t *>(_attr.stack_mem);
117120
_attr.stack_mem = nullptr;
118121
}
119122
_mutex.unlock();
@@ -417,7 +420,8 @@ Thread::~Thread()
417420
// terminate is thread safe
418421
terminate();
419422
if (_dynamic_stack) {
420-
delete[] _attr.stack_mem;
423+
// Cast before deallocation as delete[] does not accept void*
424+
delete[] static_cast<uint32_t *>(_attr.stack_mem);
421425
_attr.stack_mem = nullptr;
422426
}
423427
}

0 commit comments

Comments
 (0)