From 8646dd8a830225b1697dc1cafff32bba0ade84c5 Mon Sep 17 00:00:00 2001 From: Marc Mutz Date: Fri, 21 Jul 2017 12:16:53 +0200 Subject: Use QSharedPointer::create() more This is the result of running the (experimental) clang-tidy check qt-modernize-qsharedpointer-create Discarded changes: none. Change-Id: I58a0f230516e836df62b40cf8ec38a6b3d7122db Reviewed-by: Thiago Macieira Reviewed-by: Alex Blasche --- src/bluetooth/qbluetoothserviceinfo.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/bluetooth') diff --git a/src/bluetooth/qbluetoothserviceinfo.cpp b/src/bluetooth/qbluetoothserviceinfo.cpp index d2920d78..e4e5d1ed 100644 --- a/src/bluetooth/qbluetoothserviceinfo.cpp +++ b/src/bluetooth/qbluetoothserviceinfo.cpp @@ -342,7 +342,7 @@ bool QBluetoothServiceInfo::unregisterService() Construct a new invalid QBluetoothServiceInfo; */ QBluetoothServiceInfo::QBluetoothServiceInfo() - : d_ptr(QSharedPointer(new QBluetoothServiceInfoPrivate)) + : d_ptr(QSharedPointer::create()) { } -- cgit v1.2.3 From e9cb913a37318284353790f46edc648a630d758f Mon Sep 17 00:00:00 2001 From: Oliver Wolff Date: Tue, 1 Aug 2017 15:44:13 +0200 Subject: winrt: Check for valid m_socketObject before accessing socket information If the socket was created without giving the socket type, ensureNativeSocket was not called and thus m_socketObject is 0. Calling localName and friends caused a crash because they accesses the object unconditionally. Change-Id: I442e3d1492458161fb8660f1b2f17d52b37a2935 Reviewed-by: Alex Blasche --- src/bluetooth/qbluetoothsocket_winrt.cpp | 15 +++++++++++++++ 1 file changed, 15 insertions(+) (limited to 'src/bluetooth') diff --git a/src/bluetooth/qbluetoothsocket_winrt.cpp b/src/bluetooth/qbluetoothsocket_winrt.cpp index 4a9d1b93..501ffd74 100644 --- a/src/bluetooth/qbluetoothsocket_winrt.cpp +++ b/src/bluetooth/qbluetoothsocket_winrt.cpp @@ -422,6 +422,9 @@ QString QBluetoothSocketPrivate::localName() const QBluetoothAddress QBluetoothSocketPrivate::localAddress() const { + if (!m_socketObject) + return QBluetoothAddress(); + HRESULT hr; ComPtr info; hr = m_socketObject->get_Information(&info); @@ -437,6 +440,9 @@ QBluetoothAddress QBluetoothSocketPrivate::localAddress() const quint16 QBluetoothSocketPrivate::localPort() const { + if (!m_socketObject) + return 0; + HRESULT hr; ComPtr info; hr = m_socketObject->get_Information(&info); @@ -449,6 +455,9 @@ quint16 QBluetoothSocketPrivate::localPort() const QString QBluetoothSocketPrivate::peerName() const { + if (!m_socketObject) + return QString(); + HRESULT hr; ComPtr info; hr = m_socketObject->get_Information(&info); @@ -464,6 +473,9 @@ QString QBluetoothSocketPrivate::peerName() const QBluetoothAddress QBluetoothSocketPrivate::peerAddress() const { + if (!m_socketObject) + return QBluetoothAddress(); + HRESULT hr; ComPtr info; hr = m_socketObject->get_Information(&info); @@ -479,6 +491,9 @@ QBluetoothAddress QBluetoothSocketPrivate::peerAddress() const quint16 QBluetoothSocketPrivate::peerPort() const { + if (!m_socketObject) + return 0; + HRESULT hr; ComPtr info; hr = m_socketObject->get_Information(&info); -- cgit v1.2.3 From d1d06bf7ad2f0c02165f17904d219fc535477f25 Mon Sep 17 00:00:00 2001 From: Oliver Wolff Date: Thu, 3 Aug 2017 11:15:11 +0200 Subject: winrt: Fix crash in QBluetoothServer::nextPendingConnection If there are no pending connections, the call should not make the application crash but just return nullptr. Change-Id: I33c2ec9b47bbb72abc99ad22035f794724b295ef Reviewed-by: Alex Blasche --- src/bluetooth/qbluetoothserver_winrt.cpp | 2 ++ 1 file changed, 2 insertions(+) (limited to 'src/bluetooth') diff --git a/src/bluetooth/qbluetoothserver_winrt.cpp b/src/bluetooth/qbluetoothserver_winrt.cpp index 61134c1f..ddd71c21 100644 --- a/src/bluetooth/qbluetoothserver_winrt.cpp +++ b/src/bluetooth/qbluetoothserver_winrt.cpp @@ -217,6 +217,8 @@ bool QBluetoothServer::hasPendingConnections() const QBluetoothSocket *QBluetoothServer::nextPendingConnection() { Q_D(QBluetoothServer); + if (d->pendingConnections.count() == 0) + return nullptr; ComPtr socket = d->pendingConnections.takeFirst(); -- cgit v1.2.3 From 687ec9eb370e9538264280b58bed4d3b1c889579 Mon Sep 17 00:00:00 2001 From: Alex Blasche Date: Wed, 2 Aug 2017 11:53:54 +0200 Subject: Avoid recursion during QBluetoothDeviceDiscoveryAgent::stop() QBluetoothDeviceDiscoveryAgent (DDA) is deleted by QBluetoothServiceDiscoveryAgent (SDA) once it receives an error or SDA is instructed to stop() the discovery process. Currently, this triggers at least two calls to the DDA's stop() function. In addition, if stop() generates an error the error call itself will call back to DDA:stop(). Therefore it create an endless loop back. This is at least true for the Android devices mentioned in the related bug report. This patch ensures that the main logic of Android's DDA::stop() is not called more than once. Further more SDA disconnects from DDA's signals to avoid a potential endless loop. Any error in DDA is not of relevance to the surrounding SDA instance anymore. Task-number: QTBUG-60131 Change-Id: I1df16f2b0896928833aa2ced75c43d4642b4fba3 Reviewed-by: Timur Pocheptsov --- src/bluetooth/qbluetoothdevicediscoveryagent_android.cpp | 3 +++ src/bluetooth/qbluetoothservicediscoveryagent.cpp | 8 ++++++++ 2 files changed, 11 insertions(+) (limited to 'src/bluetooth') diff --git a/src/bluetooth/qbluetoothdevicediscoveryagent_android.cpp b/src/bluetooth/qbluetoothdevicediscoveryagent_android.cpp index ed6507f3..7e8e4236 100644 --- a/src/bluetooth/qbluetoothdevicediscoveryagent_android.cpp +++ b/src/bluetooth/qbluetoothdevicediscoveryagent_android.cpp @@ -225,6 +225,9 @@ void QBluetoothDeviceDiscoveryAgentPrivate::stop() return; if (m_active == SDPScanActive) { + if (pendingCancel) + return; + pendingCancel = true; pendingStart = false; bool success = adapter.callMethod("cancelDiscovery"); diff --git a/src/bluetooth/qbluetoothservicediscoveryagent.cpp b/src/bluetooth/qbluetoothservicediscoveryagent.cpp index 7daab4b7..d6163f0e 100644 --- a/src/bluetooth/qbluetoothservicediscoveryagent.cpp +++ b/src/bluetooth/qbluetoothservicediscoveryagent.cpp @@ -450,6 +450,10 @@ void QBluetoothServiceDiscoveryAgentPrivate::startDeviceDiscovery() */ void QBluetoothServiceDiscoveryAgentPrivate::stopDeviceDiscovery() { + // disconnect to avoid recursion during stop() - QTBUG-60131 + // we don't care about a potential signals from device discovery agent anymore + deviceDiscoveryAgent->disconnect(); + deviceDiscoveryAgent->stop(); delete deviceDiscoveryAgent; deviceDiscoveryAgent = 0; @@ -497,6 +501,10 @@ void QBluetoothServiceDiscoveryAgentPrivate::_q_deviceDiscoveryError(QBluetoothD error = static_cast(newError); errorString = deviceDiscoveryAgent->errorString(); + // disconnect to avoid recursion during stop() - QTBUG-60131 + // we don't care about a potential signals from device discovery agent anymore + deviceDiscoveryAgent->disconnect(); + deviceDiscoveryAgent->stop(); delete deviceDiscoveryAgent; deviceDiscoveryAgent = 0; -- cgit v1.2.3