QModbusTcpServer: fix memory leak


Noticed while improving Modbus Custom Command example.

Before the patch the QTcpSocket::destroyed signal was connected to
a lambda in context of the parent QTcpServer (the 'q' variable).

When the application was closed without disconnecting the server in
advance, the QTcpServer::close() was called in the server's destructor.
The client sockets were disconnected, but by the time their destructors
were called, the parent QTcpSocket was already in its desctuctor, so
the connection was destroyed (because deleteChildren() is called after
invalidating connections in QObject's d-tor).

This patch simply changes the context of the lambda's connection to
the socket object itself, so that the lamdba is correctly invoked
from the socket's destructor.

Pick-to: 6.5 6.4 6.2
Change-Id: I04e196645db35c390a2bb255f1fadaac336fec25
Reviewed-by: MÃ¥rten Nordheim <marten.nordheim@qt.io>
commitbfb62b60ad6873ad1912df0f08ce9cf7fd80447b
parent0ac11c92929449cd77c9e867be329bf56eba8d94
authorIvan Solovev <ivan.solovev@qt.io>
committerIvan Solovev <ivan.solovev@qt.io>
commit timeThu, 9 Feb 2023 10:11:49 +0100