diff options
author | Alex Blasche <alexander.blasche@qt.io> | 2019-05-07 16:04:59 +0200 |
---|---|---|
committer | Alex Blasche <alexander.blasche@qt.io> | 2019-05-08 15:24:25 +0200 |
commit | d67ca376b2111717de88596888f315fba05ef9c3 (patch) | |
tree | d3c3998e5aeaed2f39afe5b95835344f859fddda /src | |
parent | 14b0efe1d4e5addec5f577a2d01a3a0d9a1d931b (diff) |
BlueZ: Fix leaking client socket when running QLEController Peripheral mode
In fact there are two socket leaks. The first is the socket for the incoming
l2cp connection from the central device and the second one is allocated in the
ctor of QBluetoothSocket. When QBluetoothSocket::setSocketDescriptor is called
the previously ctor allocated socket was simply ignorred. This patch closes
both socket.
Fixes: QTBUG-75278
Change-Id: Ia483e3c2a04bec3a53ddf744c22b794941edf848
Reviewed-by: Timur Pocheptsov <timur.pocheptsov@qt.io>
Reviewed-by: Oliver Wolff <oliver.wolff@qt.io>
Diffstat (limited to 'src')
-rw-r--r-- | src/bluetooth/qbluetoothsocket_bluez.cpp | 3 | ||||
-rw-r--r-- | src/bluetooth/qlowenergycontroller_bluez.cpp | 8 |
2 files changed, 11 insertions, 0 deletions
diff --git a/src/bluetooth/qbluetoothsocket_bluez.cpp b/src/bluetooth/qbluetoothsocket_bluez.cpp index bbc32a90..25f07bb3 100644 --- a/src/bluetooth/qbluetoothsocket_bluez.cpp +++ b/src/bluetooth/qbluetoothsocket_bluez.cpp @@ -674,6 +674,9 @@ bool QBluetoothSocketPrivateBluez::setSocketDescriptor(int socketDescriptor, QBl connectWriteNotifier = nullptr; socketType = socketType_; + if (socket != -1) + QT_CLOSE(socket); + socket = socketDescriptor; // ensure that O_NONBLOCK is set on new connections. diff --git a/src/bluetooth/qlowenergycontroller_bluez.cpp b/src/bluetooth/qlowenergycontroller_bluez.cpp index 65f4e0c2..dfa21004 100644 --- a/src/bluetooth/qlowenergycontroller_bluez.cpp +++ b/src/bluetooth/qlowenergycontroller_bluez.cpp @@ -3115,6 +3115,14 @@ void QLowEnergyControllerPrivateBluez::handleConnectionRequest() if (connectionHandle == 0) qCWarning(QT_BT_BLUEZ) << "Received client connection, but no connection complete event"; + if (l2cpSocket) { + disconnect(l2cpSocket); + if (l2cpSocket->isOpen()) + l2cpSocket->close(); + + l2cpSocket->deleteLater(); + l2cpSocket = nullptr; + } closeServerSocket(); QBluetoothSocketPrivateBluez *rawSocketPrivate = new QBluetoothSocketPrivateBluez(); |