mirror of
https://github.com/wesnoth/wesnoth
synced 2025-05-01 22:51:16 +00:00
Fix undefined behavior on destroying an event context
The destructor of the context class accidentally incremented the iterator twice per iteration. If the number of event handlers was odd, the destructor ended up incrementing the end iterator, which is UB. I rewrote the whole destructor. It's unnecessary to manually remove event handlers from the list because the list will do it automatically when it's destroyed.
This commit is contained in:
parent
681322bf29
commit
8a296386e3
@ -132,15 +132,15 @@ void context::set_focus(const sdl_handler* ptr)
|
||||
|
||||
context::~context()
|
||||
{
|
||||
if (!handlers.empty()) {
|
||||
for (handler_list::iterator it = handlers.begin(); it != handlers.end(); ++it) {
|
||||
if ((*it)->has_joined()) {
|
||||
(*it)->has_joined_ = false;
|
||||
}
|
||||
if ((*it)->has_joined_global()) {
|
||||
(*it)->has_joined_global_ = false;
|
||||
}
|
||||
it = handlers.erase(it);
|
||||
for (sdl_handler* h : handlers)
|
||||
{
|
||||
if (h->has_joined())
|
||||
{
|
||||
h->has_joined_ = false;
|
||||
}
|
||||
if (h->has_joined_global())
|
||||
{
|
||||
h->has_joined_global_ = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user