Skip to content

Commit

Permalink
Fix occasional crash on exit because of statis network access manager
Browse files Browse the repository at this point in the history
  • Loading branch information
m-kuhn committed Nov 8, 2014
1 parent f3eeed9 commit 95f880a
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 8 deletions.
3 changes: 3 additions & 0 deletions src/core/qgsapplication.cpp
Expand Up @@ -17,6 +17,7 @@
#include "qgslogger.h"
#include "qgsmaplayerregistry.h"
#include "qgsproviderregistry.h"
#include "qgsnetworkaccessmanager.h"
#include "qgsexception.h"
#include "qgsgeometry.h"

Expand Down Expand Up @@ -609,6 +610,8 @@ void QgsApplication::exitQgis()
delete QgsMapLayerRegistry::instance();

delete QgsProviderRegistry::instance();

delete QgsNetworkAccessManager::instance();
}

QString QgsApplication::showSettings()
Expand Down
13 changes: 10 additions & 3 deletions src/core/qgsnetworkaccessmanager.cpp
Expand Up @@ -86,10 +86,17 @@ class QgsNetworkProxyFactory : public QNetworkProxyFactory
}
};

QgsNetworkAccessManager *QgsNetworkAccessManager::instance()
//
// Static calls to enforce singleton behaviour
//
QgsNetworkAccessManager* QgsNetworkAccessManager::sInstance = 0;
QgsNetworkAccessManager* QgsNetworkAccessManager::instance()
{
static QgsNetworkAccessManager sInstance;
return &sInstance;
if ( sInstance == 0 )
{
sInstance = new QgsNetworkAccessManager();
}
return sInstance;
}

QgsNetworkAccessManager::QgsNetworkAccessManager( QObject *parent )
Expand Down
3 changes: 2 additions & 1 deletion src/core/qgsnetworkaccessmanager.h
Expand Up @@ -48,7 +48,7 @@ class CORE_EXPORT QgsNetworkAccessManager : public QNetworkAccessManager
public:
//! returns a pointer to the single instance
// and creates that instance on the first call.
static QgsNetworkAccessManager *instance();
static QgsNetworkAccessManager* instance();

QgsNetworkAccessManager( QObject *parent = 0 );

Expand Down Expand Up @@ -100,6 +100,7 @@ class CORE_EXPORT QgsNetworkAccessManager : public QNetworkAccessManager
QNetworkProxy mFallbackProxy;
QStringList mExcludedURLs;
bool mUseSystemProxy;
static QgsNetworkAccessManager* sInstance;
};

#endif // QGSNETWORKACCESSMANAGER_H
Expand Down
8 changes: 4 additions & 4 deletions tests/src/core/testqgsnetworkcontentfetcher.cpp
Expand Up @@ -16,6 +16,7 @@
***************************************************************************/

#include "qgsnetworkcontentfetcher.h"
#include "qgsapplication.h"
#include <QObject>
#include <QtTest>
#include <QNetworkReply>
Expand Down Expand Up @@ -44,22 +45,21 @@ class TestQgsNetworkContentFetcher: public QObject

void TestQgsNetworkContentFetcher::initTestCase()
{

QgsApplication::init();
QgsApplication::initQgis();
}

void TestQgsNetworkContentFetcher::cleanupTestCase()
{

QgsApplication::exitQgis();
}

void TestQgsNetworkContentFetcher::init()
{

}

void TestQgsNetworkContentFetcher::cleanup()
{

}

void TestQgsNetworkContentFetcher::fetchEmptyUrl()
Expand Down

0 comments on commit 95f880a

Please sign in to comment.