Fix crash when app is going to shutdown but conf manager is requested

If the app is finished and going to shutdown,
qNetworkConfigurationManagerPrivate() returns nullptr.

Change-Id: I01915021d8698802b3a1d0dee43203cd3d4aba74
Task-number: QTBUG-76090
Reviewed-by: Mårten Nordheim <marten.nordheim@qt.io>
This commit is contained in:
Val Doroshchuk 2019-05-31 14:15:53 +02:00 committed by VaL Doroshchuk
parent 93642992ae
commit 9b6928b7cc
3 changed files with 22 additions and 19 deletions

View File

@ -233,19 +233,20 @@ QNetworkConfigurationManager::QNetworkConfigurationManager(QObject *parent)
: QObject(parent) : QObject(parent)
{ {
QNetworkConfigurationManagerPrivate *priv = qNetworkConfigurationManagerPrivate(); 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)), priv->enablePolling();
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();
} }
/*! /*!

View File

@ -258,7 +258,8 @@ QNetworkSession::QNetworkSession(const QNetworkConfiguration &connectionConfig,
// invalid configuration // invalid configuration
if (!connectionConfig.identifier().isEmpty()) { if (!connectionConfig.identifier().isEmpty()) {
const auto engines = qNetworkConfigurationManagerPrivate()->engines(); auto priv = qNetworkConfigurationManagerPrivate();
const auto engines = priv ? priv->engines() : QList<QBearerEngine *>();
for (QBearerEngine *engine : engines) { for (QBearerEngine *engine : engines) {
if (engine->hasIdentifier(connectionConfig.identifier())) { if (engine->hasIdentifier(connectionConfig.identifier())) {
d = engine->createSessionBackend(); d = engine->createSessionBackend();

View File

@ -56,12 +56,13 @@ QT_BEGIN_NAMESPACE
static QBearerEngineImpl *getEngineFromId(const QString &id) static QBearerEngineImpl *getEngineFromId(const QString &id)
{ {
QNetworkConfigurationManagerPrivate *priv = qNetworkConfigurationManagerPrivate(); QNetworkConfigurationManagerPrivate *priv = qNetworkConfigurationManagerPrivate();
if (priv) {
const auto engines = priv->engines(); const auto engines = priv->engines();
for (QBearerEngine *engine : engines) { for (QBearerEngine *engine : engines) {
QBearerEngineImpl *engineImpl = qobject_cast<QBearerEngineImpl *>(engine); QBearerEngineImpl *engineImpl = qobject_cast<QBearerEngineImpl *>(engine);
if (engineImpl && engineImpl->hasIdentifier(id)) if (engineImpl && engineImpl->hasIdentifier(id))
return engineImpl; return engineImpl;
}
} }
return 0; return 0;