Skip to content

Commit

Permalink
server: Z21 ClientKernel fix crash on disconnect
Browse files Browse the repository at this point in the history
See traintastic#53
When disabling communications, kernel object is deleted
but EventLoop callback will run after and access deleted
object through captured 'this'
Temporary fix for this problem is to copy log ID value instead.
  • Loading branch information
gfgit committed Nov 2, 2023
1 parent a915d5e commit d9ace24
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions server/src/hardware/protocol/z21/clientkernel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -53,9 +53,9 @@ void ClientKernel::receive(const Message& message)
{
if(m_config.debugLogRXTX)
EventLoop::call(
[this, msg=toString(message)]()
[logId_=logId, msg=toString(message)]()
{
Log::log(logId, LogMessage::D2002_RX_X, msg);
Log::log(logId_, LogMessage::D2002_RX_X, msg);
});

switch(message.header())
Expand Down Expand Up @@ -519,9 +519,9 @@ void ClientKernel::send(const Message& message)
{
if(m_config.debugLogRXTX)
EventLoop::call(
[this, msg=toString(message)]()
[logId_=logId, msg=toString(message)]()
{
Log::log(logId, LogMessage::D2001_TX_X, msg);
Log::log(logId_, LogMessage::D2001_TX_X, msg);
});
}
else
Expand Down

0 comments on commit d9ace24

Please sign in to comment.