Fix uses of std::remove_if
std::remove_if is not std::partition, it makes no guarantees on the state of the objects past the new end (they usually are in a moved-from state).
This commit is contained in:
parent
8135a44c6c
commit
924f30840b
|
@ -153,18 +153,22 @@ void ClientManager::ensure_no_client_uses_buffer(Buffer& buffer)
|
||||||
Buffer* last = client->last_buffer();
|
Buffer* last = client->last_buffer();
|
||||||
context.change_buffer(last ? *last : BufferManager::instance().get_first_buffer());
|
context.change_buffer(last ? *last : BufferManager::instance().get_first_buffer());
|
||||||
}
|
}
|
||||||
auto end = std::remove_if(m_free_windows.begin(), m_free_windows.end(),
|
Vector<std::unique_ptr<Window>> removed_windows;
|
||||||
[&buffer](const WindowAndSelections& ws)
|
m_free_windows.erase(std::remove_if(m_free_windows.begin(), m_free_windows.end(),
|
||||||
{ return &ws.window->buffer() == &buffer; });
|
[&buffer, &removed_windows](WindowAndSelections& ws) {
|
||||||
|
if (&ws.window->buffer() != &buffer)
|
||||||
|
return false;
|
||||||
|
removed_windows.push_back(std::move(ws.window));
|
||||||
|
return true;
|
||||||
|
}),
|
||||||
|
m_free_windows.end());
|
||||||
|
|
||||||
for (auto it = end; it != m_free_windows.end(); ++it)
|
for (auto&& removed_window : removed_windows)
|
||||||
{
|
{
|
||||||
auto& win = it->window;
|
removed_window->run_hook_in_own_context(Hook::WinClose,
|
||||||
win->run_hook_in_own_context(Hook::WinClose, win->buffer().name());
|
removed_window->buffer().name());
|
||||||
m_window_trash.push_back(std::move(win));
|
m_window_trash.push_back(std::move(removed_window));
|
||||||
}
|
}
|
||||||
|
|
||||||
m_free_windows.erase(end, m_free_windows.end());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void ClientManager::clear_window_trash()
|
void ClientManager::clear_window_trash()
|
||||||
|
|
|
@ -36,13 +36,14 @@ void HookManager::remove_hooks(const Regex& regex)
|
||||||
{
|
{
|
||||||
for (auto& list : m_hooks)
|
for (auto& list : m_hooks)
|
||||||
{
|
{
|
||||||
auto it = std::remove_if(list.begin(), list.end(),
|
list.erase(std::remove_if(list.begin(), list.end(),
|
||||||
[&](const std::unique_ptr<HookData>& h)
|
[this, ®ex](std::unique_ptr<HookData>& h) {
|
||||||
{ return regex_match(h->group.begin(), h->group.end(), regex); });
|
if (not regex_match(h->group.begin(), h->group.end(), regex))
|
||||||
if (not m_running_hooks.empty()) // we are running some hooks, defer deletion
|
return false;
|
||||||
m_hooks_trash.insert(m_hooks_trash.end(), std::make_move_iterator(it),
|
m_hooks_trash.push_back(std::move(h));
|
||||||
std::make_move_iterator(list.end()));
|
return true;
|
||||||
list.erase(it, list.end());
|
}),
|
||||||
|
list.end());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user