Avoid potentially using unit IDs that are no longer valid

Resolves #6603 (crash with musl implementation of libc)
This commit is contained in:
Wedge009 2022-04-08 11:10:00 +10:00 committed by Steve Cotton
parent c1d7e65cbc
commit aa6b5b493d
2 changed files with 4 additions and 1 deletions

View file

@ -23,6 +23,7 @@
### WML Engine
### Miscellaneous and Bug Fixes
* Reduced the size of Isar's Cross map background images.
* Resolve crash on systems using musl implementation of libc (issue #6603)
## Version 1.17.2
### Add-ons client

View file

@ -56,8 +56,10 @@ unit_const_ptr recall_list_manager::find_if_matches_id(const std::string &unit_i
*/
void recall_list_manager::erase_if_matches_id(const std::string &unit_id)
{
// using unit_id as reference has potential to cause a crash if the underlying unit becomes invald
// https://github.com/wesnoth/wesnoth/issues/6603
recall_list_.erase(std::remove_if(recall_list_.begin(), recall_list_.end(),
[&unit_id](const unit_ptr & ptr) { return ptr->id() == unit_id; }),
[unit_id](const unit_ptr & ptr) { return ptr->id() == unit_id; }),
recall_list_.end());
}