[Libreoffice-commits] core.git: sd/source

Andrzej Hunt (via logerrit) logerrit at kemper.freedesktop.org
Sat Jul 24 07:52:09 UTC 2021


 sd/source/ui/remotecontrol/BufferedStreamSocket.cxx |    4 ++++
 sd/source/ui/remotecontrol/BufferedStreamSocket.hxx |    5 ++++-
 2 files changed, 8 insertions(+), 1 deletion(-)

New commits:
commit 2855f12072023930a15ea852e40d05de4a6be164
Author:     Andrzej Hunt <andrzej at ahunt.org>
AuthorDate: Sat Jul 17 09:42:47 2021 +0200
Commit:     Andrzej Hunt <andrzej at ahunt.org>
CommitDate: Sat Jul 24 09:51:36 2021 +0200

    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 at ahunt.org>

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


More information about the Libreoffice-commits mailing list