Skip to content

Fix crash due to access after delete#3449

Merged
zimmy87 merged 2 commits intomicrosoft:masterfrom
rajat2004:fix-signal-delete-crash
Mar 8, 2021
Merged

Fix crash due to access after delete#3449
zimmy87 merged 2 commits intomicrosoft:masterfrom
rajat2004:fix-signal-delete-crash

Conversation

@rajat2004
Copy link
Copy Markdown
Contributor

@rajat2004 rajat2004 commented Mar 7, 2021

Fixes: #3448
Fixes: #3452

About

This PR fixes a crash due to access after erase in the map. #3402 added a method that is only supposed to be called once, and after that removes itself. However, the range-based for loop is not suitable for this and causes a crash after the method returns due to the iterator now essentially being invalid. Also, see https://stackoverflow.com/questions/8234779/how-to-remove-from-a-map-while-iterating-it/8234813

The second commit adds some cleanup, it isn't actually required but makes things clearer. Can be easily dropped if not preferred

How Has This Been Tested?

Currently only tested with the default multirotor. Also tested by starting and stopping the play and using debug statements to make sure that things are working correctly and no extra items are added to the array

Screenshots (if appropriate):

@ahmed-elsaharti
Copy link
Copy Markdown
Contributor

Tested on both Windows and Ubuntu. Works perfectly and makes complete sense.
Good job tracking this down to the range-based for loop @rajat2004 👍

@zimmy87
Copy link
Copy Markdown
Contributor

zimmy87 commented Mar 8, 2021

Tested this locally on windows and ubuntu and it works for me as well, so I'm going ahead and merging this.

@zimmy87 zimmy87 merged commit b5d2f25 into microsoft:master Mar 8, 2021
@rajat2004 rajat2004 deleted the fix-signal-delete-crash branch March 9, 2021 03:10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

3 participants