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>
This commit is contained in:
Alex Blasche 2019-05-07 16:04:59 +02:00
parent 14b0efe1d4
commit d67ca376b2
2 changed files with 11 additions and 0 deletions

View File

@ -674,6 +674,9 @@ bool QBluetoothSocketPrivateBluez::setSocketDescriptor(int socketDescriptor, QBl
connectWriteNotifier = nullptr; connectWriteNotifier = nullptr;
socketType = socketType_; socketType = socketType_;
if (socket != -1)
QT_CLOSE(socket);
socket = socketDescriptor; socket = socketDescriptor;
// ensure that O_NONBLOCK is set on new connections. // ensure that O_NONBLOCK is set on new connections.

View File

@ -3115,6 +3115,14 @@ void QLowEnergyControllerPrivateBluez::handleConnectionRequest()
if (connectionHandle == 0) if (connectionHandle == 0)
qCWarning(QT_BT_BLUEZ) << "Received client connection, but no connection complete event"; 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(); closeServerSocket();
QBluetoothSocketPrivateBluez *rawSocketPrivate = new QBluetoothSocketPrivateBluez(); QBluetoothSocketPrivateBluez *rawSocketPrivate = new QBluetoothSocketPrivateBluez();