1
1
mirror of https://github.com/mawww/kakoune.git synced 2024-12-26 21:22:00 +03:00

Fix use after delete in RemoteClient FDWatcher callback

Fixes #2357
This commit is contained in:
Maxime Coste 2018-09-07 09:08:04 +10:00
parent 15bb23865a
commit 14f9f4c468

View File

@ -583,12 +583,11 @@ RemoteClient::RemoteClient(StringView session, StringView name, std::unique_ptr<
m_socket_watcher->events() |= FdEvents::Write; m_socket_watcher->events() |= FdEvents::Write;
}); });
MsgReader reader;
m_socket_watcher.reset(new FDWatcher{sock, FdEvents::Read | FdEvents::Write, m_socket_watcher.reset(new FDWatcher{sock, FdEvents::Read | FdEvents::Write,
[this, reader](FDWatcher& watcher, FdEvents events, EventMode) mutable { [this, reader = MsgReader{}](FDWatcher& watcher, FdEvents events, EventMode) mutable {
const int sock = watcher.fd(); const int sock = watcher.fd();
if (events & FdEvents::Write and send_data(sock, m_send_buffer)) if (events & FdEvents::Write and send_data(sock, m_send_buffer))
m_socket_watcher->events() &= ~FdEvents::Write; watcher.events() &= ~FdEvents::Write;
while (events & FdEvents::Read and while (events & FdEvents::Read and
not reader.ready() and fd_readable(sock)) not reader.ready() and fd_readable(sock))
@ -661,9 +660,8 @@ RemoteClient::RemoteClient(StringView session, StringView name, std::unique_ptr<
break; break;
case MessageType::Exit: case MessageType::Exit:
m_exit_status = reader.read<int>(); m_exit_status = reader.read<int>();
m_socket_watcher->close_fd(); watcher.close_fd();
m_socket_watcher.reset(); return;
return; // This lambda is now dead
default: default:
kak_assert(false); kak_assert(false);
} }