From 9b6928b7cc6f12638ae625c67ecf437cfc694498 Mon Sep 17 00:00:00 2001 From: Val Doroshchuk Date: Fri, 31 May 2019 14:15:53 +0200 Subject: [PATCH] Fix crash when app is going to shutdown but conf manager is requested MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit If the app is finished and going to shutdown, qNetworkConfigurationManagerPrivate() returns nullptr. Change-Id: I01915021d8698802b3a1d0dee43203cd3d4aba74 Task-number: QTBUG-76090 Reviewed-by: MÃ¥rten Nordheim --- src/network/bearer/qnetworkconfigmanager.cpp | 25 ++++++++++---------- src/network/bearer/qnetworksession.cpp | 3 ++- src/plugins/bearer/qnetworksession_impl.cpp | 13 +++++----- 3 files changed, 22 insertions(+), 19 deletions(-) diff --git a/src/network/bearer/qnetworkconfigmanager.cpp b/src/network/bearer/qnetworkconfigmanager.cpp index 81b5e01d6a..cd87c3669c 100644 --- a/src/network/bearer/qnetworkconfigmanager.cpp +++ b/src/network/bearer/qnetworkconfigmanager.cpp @@ -233,19 +233,20 @@ QNetworkConfigurationManager::QNetworkConfigurationManager(QObject *parent) : QObject(parent) { QNetworkConfigurationManagerPrivate *priv = qNetworkConfigurationManagerPrivate(); + if (priv) { + connect(priv, SIGNAL(configurationAdded(QNetworkConfiguration)), + this, SIGNAL(configurationAdded(QNetworkConfiguration))); + connect(priv, SIGNAL(configurationRemoved(QNetworkConfiguration)), + this, SIGNAL(configurationRemoved(QNetworkConfiguration))); + connect(priv, SIGNAL(configurationChanged(QNetworkConfiguration)), + this, SIGNAL(configurationChanged(QNetworkConfiguration))); + connect(priv, SIGNAL(onlineStateChanged(bool)), + this, SIGNAL(onlineStateChanged(bool))); + connect(priv, SIGNAL(configurationUpdateComplete()), + this, SIGNAL(updateCompleted())); - connect(priv, SIGNAL(configurationAdded(QNetworkConfiguration)), - this, SIGNAL(configurationAdded(QNetworkConfiguration))); - connect(priv, SIGNAL(configurationRemoved(QNetworkConfiguration)), - this, SIGNAL(configurationRemoved(QNetworkConfiguration))); - connect(priv, SIGNAL(configurationChanged(QNetworkConfiguration)), - this, SIGNAL(configurationChanged(QNetworkConfiguration))); - connect(priv, SIGNAL(onlineStateChanged(bool)), - this, SIGNAL(onlineStateChanged(bool))); - connect(priv, SIGNAL(configurationUpdateComplete()), - this, SIGNAL(updateCompleted())); - - priv->enablePolling(); + priv->enablePolling(); + } } /*! diff --git a/src/network/bearer/qnetworksession.cpp b/src/network/bearer/qnetworksession.cpp index 471d322998..1636bcee97 100644 --- a/src/network/bearer/qnetworksession.cpp +++ b/src/network/bearer/qnetworksession.cpp @@ -258,7 +258,8 @@ QNetworkSession::QNetworkSession(const QNetworkConfiguration &connectionConfig, // invalid configuration if (!connectionConfig.identifier().isEmpty()) { - const auto engines = qNetworkConfigurationManagerPrivate()->engines(); + auto priv = qNetworkConfigurationManagerPrivate(); + const auto engines = priv ? priv->engines() : QList(); for (QBearerEngine *engine : engines) { if (engine->hasIdentifier(connectionConfig.identifier())) { d = engine->createSessionBackend(); diff --git a/src/plugins/bearer/qnetworksession_impl.cpp b/src/plugins/bearer/qnetworksession_impl.cpp index 847479047f..903525a204 100644 --- a/src/plugins/bearer/qnetworksession_impl.cpp +++ b/src/plugins/bearer/qnetworksession_impl.cpp @@ -56,12 +56,13 @@ QT_BEGIN_NAMESPACE static QBearerEngineImpl *getEngineFromId(const QString &id) { QNetworkConfigurationManagerPrivate *priv = qNetworkConfigurationManagerPrivate(); - - const auto engines = priv->engines(); - for (QBearerEngine *engine : engines) { - QBearerEngineImpl *engineImpl = qobject_cast(engine); - if (engineImpl && engineImpl->hasIdentifier(id)) - return engineImpl; + if (priv) { + const auto engines = priv->engines(); + for (QBearerEngine *engine : engines) { + QBearerEngineImpl *engineImpl = qobject_cast(engine); + if (engineImpl && engineImpl->hasIdentifier(id)) + return engineImpl; + } } return 0;