Skip to content

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

Merged

Conversation

hugueskamba
Copy link
Collaborator

@hugueskamba hugueskamba commented Sep 2, 2019

Description

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 request type

[X] Fix
[ ] Refactor
[ ] Target update
[ ] Functionality change
[ ] Docs update
[ ] Test update
[ ] Breaking change

Reviewers

@kjbracey-arm @evedon

Release Notes

@ciarmcom ciarmcom requested review from evedon, kjbracey and a team September 2, 2019 15:00
@ciarmcom
Copy link
Member

ciarmcom commented Sep 2, 2019

@hugueskamba, thank you for your changes.
@kjbracey-arm @evedon @ARMmbed/mbed-os-core @ARMmbed/mbed-os-maintainers please review.

@ciarmcom ciarmcom requested a review from a team September 2, 2019 15:00
@@ -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);
Copy link
Contributor

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 *.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@kjbracey
Copy link
Contributor

kjbracey commented Sep 3, 2019

Fine, except the Git commit message and GitHub title/description need to be updated.

@hugueskamba hugueskamba force-pushed the hk-fix-thread-stack-mem-deallocation branch from d25dc43 to 955dbce Compare September 3, 2019 09:49
@hugueskamba hugueskamba changed the title Deallocate stack memory with free instead of delete[] Cast void pointer before deallocating with delete[] Sep 3, 2019
@hugueskamba
Copy link
Collaborator Author

Fine, except the Git commit message and GitHub title/description need to be updated.

Done

@@ -19,6 +19,8 @@
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/

#include <stdlib.h>
Copy link
Contributor

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.

Copy link
Collaborator Author

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.
@hugueskamba hugueskamba force-pushed the hk-fix-thread-stack-mem-deallocation branch from 955dbce to a562841 Compare September 3, 2019 09:52
@0xc0170
Copy link
Contributor

0xc0170 commented Sep 3, 2019

CI started

@mbed-ci
Copy link

mbed-ci commented Sep 3, 2019

Test run: FAILED

Summary: 1 of 4 test jobs failed
Build number : 1
Build artifacts

Failed test jobs:

  • jenkins-ci/mbed-os-ci_build-ARM

@hugueskamba
Copy link
Collaborator Author

Test run: FAILED

Summary: 1 of 4 test jobs failed
Build number : 1
Build artifacts

Failed test jobs:

  • jenkins-ci/mbed-os-ci_build-ARM

@0xc0170
Is the failure a fluke or do we really think it was caused by this seemingly minor change?

@0xc0170
Copy link
Contributor

0xc0170 commented Sep 4, 2019

CI restarted

@mbed-ci
Copy link

mbed-ci commented Sep 4, 2019

Test run: SUCCESS

Summary: 11 of 11 test jobs passed
Build number : 2
Build artifacts

@0xc0170 0xc0170 merged commit be769c0 into ARMmbed:master Sep 4, 2019
@hugueskamba hugueskamba deleted the hk-fix-thread-stack-mem-deallocation branch September 10, 2019 07:54
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants