diff options
author | Andrzej Hunt <andrzej@ahunt.org> | 2021-07-17 09:42:47 +0200 |
---|---|---|
committer | Andrzej Hunt <andrzej@ahunt.org> | 2021-07-24 09:51:36 +0200 |
commit | 2855f12072023930a15ea852e40d05de4a6be164 (patch) | |
tree | 8bfb464d68dfa6d2b521de695f0c32c42b08dc7f | |
parent | 77a192aa016279acc0b0f9df584d1ce31bde41a4 (diff) |
sdremote: close BufferedStreamSocket on destruction
This follows the pattern in osl::Socket which also cleans up on
destruction if necessary.
By closing on destruction we can avoid leaking the underlying socket or
filedescriptor in the numerous scenarios where we throw away the socket
without bothering to call close(). This isn't a big deal in normal
usage - we don't use many sockets in the first place - but you can
quickly run out of filedescriptors when running sufficiently complex
tests.
We also need to make BufferedStreamSocket final to avoid triggering
loplugin:fragiledestructor - BufferedStreamSocket probably should
have been final anyway, so there's no reason not to do so.
Change-Id: I90c271df4b598a6c2b326fde13543e6b27d7a110
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/119093
Tested-by: Jenkins
Reviewed-by: Andrzej Hunt <andrzej@ahunt.org>
-rw-r--r-- | sd/source/ui/remotecontrol/BufferedStreamSocket.cxx | 4 | ||||
-rw-r--r-- | sd/source/ui/remotecontrol/BufferedStreamSocket.hxx | 5 |
2 files changed, 8 insertions, 1 deletions
diff --git a/sd/source/ui/remotecontrol/BufferedStreamSocket.cxx b/sd/source/ui/remotecontrol/BufferedStreamSocket.cxx index b3a9cc154e37..58adb13ca7bf 100644 --- a/sd/source/ui/remotecontrol/BufferedStreamSocket.cxx +++ b/sd/source/ui/remotecontrol/BufferedStreamSocket.cxx @@ -47,6 +47,10 @@ BufferedStreamSocket::BufferedStreamSocket( int aSocket ): { } +BufferedStreamSocket::~BufferedStreamSocket() { + close(); +} + void BufferedStreamSocket::getPeerAddr(osl::SocketAddr& rAddr) { assert ( !usingCSocket ); diff --git a/sd/source/ui/remotecontrol/BufferedStreamSocket.hxx b/sd/source/ui/remotecontrol/BufferedStreamSocket.hxx index 08a81cf002f6..6abf7ec1bf8d 100644 --- a/sd/source/ui/remotecontrol/BufferedStreamSocket.hxx +++ b/sd/source/ui/remotecontrol/BufferedStreamSocket.hxx @@ -25,7 +25,7 @@ namespace sd * returned to being a StreamSocket wrapper if/when Bluetooth is * integrated into osl Sockets. */ - class BufferedStreamSocket : + class BufferedStreamSocket final : public IBluetoothSocket, private ::osl::StreamSocket { @@ -40,6 +40,9 @@ namespace sd */ explicit BufferedStreamSocket( int aSocket ); BufferedStreamSocket( const BufferedStreamSocket &aSocket ); + + ~BufferedStreamSocket(); + /** * Blocks until a line is read. * Returns whatever the last call of recv returned, i.e. 0 or less |