-
Notifications
You must be signed in to change notification settings - Fork 3k
Cast void pointer before deallocating with delete[] #11393
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Cast void pointer before deallocating with delete[] #11393
Conversation
@hugueskamba, thank you for your changes. |
rtos/source/Thread.cpp
Outdated
@@ -113,7 +115,7 @@ osStatus Thread::start(mbed::Callback<void()> task) | |||
_tid = osThreadNew(Thread::_thunk, this, &_attr); | |||
if (_tid == nullptr) { | |||
if (_dynamic_stack) { | |||
delete[] _attr.stack_mem; | |||
free(_attr.stack_mem); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No, not technically legal either. If it's allocated with new[]
, it has to be deleted with delete[]
.
You have to either put the cast in to name the type of the new:
delete[] static_cast<uint32_t *>(_attr.stack_mem);
Or actually arrange for the pointer to be a uint32_t *
. Putting the cast in is probably simplest for now, even if ugly.
I have a bad feeling I might have deleted the cast from there at some point, not realising it was necessary. Might be worth putting a small comment that delete[]
does not accept void *
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
64f693c
to
d25dc43
Compare
Fine, except the Git commit message and GitHub title/description need to be updated. |
d25dc43
to
955dbce
Compare
Done |
rtos/source/Thread.cpp
Outdated
@@ -19,6 +19,8 @@ | |||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | |||
* SOFTWARE. | |||
*/ | |||
|
|||
#include <stdlib.h> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Missed that you don't need this any more - doesn't really matter.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just done it. 👍
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.
955dbce
to
a562841
Compare
CI started |
Test run: FAILEDSummary: 1 of 4 test jobs failed Failed test jobs:
|
@0xc0170 |
CI restarted |
Test run: SUCCESSSummary: 11 of 11 test jobs passed |
Description
The stack memory is a
void*
which creates a warning when usingthe
delete[]
operator because it is unable to call the destructor ofof an unknown object type.
Pull request type
Reviewers
@kjbracey-arm @evedon
Release Notes