fix: concurrency crash in closeAllShopWindows caused by use-after-free #3211
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Description
This PR fixes a concurrency crash in the
closeAllShopWindows
method. The issue occurred when theshopPlayers
map was cleared while being iterated over, leading to a use-after-free scenario. The solution removes the use of references when iterating overshopPlayers
keys, ensuring that the keys are copied instead of directly referencing the map. This change prevents crashes and improves stability in concurrent environments.Behaviour
Actual
shopPlayers
with references caused a crash in some scenarios because the map was cleared during the iteration, leading to use-after-free memory access.Expected
shopPlayers
no longer results in crashes because the keys are copied, ensuring safe iteration even if the map is modified during the process.Type of change
How Has This Been Tested
shopPlayers
is cleared while being iterated to validate the fix.closeAllShopWindows
under concurrent conditions without crashes.Checklist