Skip to content

Commit f2fbb2f

Browse files
committed
Cleanup methods for providers (implemented for GDAL and OGR)
Fix #8932
1 parent 0bfc766 commit f2fbb2f

File tree

3 files changed

+26
-1
lines changed

3 files changed

+26
-1
lines changed

src/core/qgsproviderregistry.cpp

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -199,8 +199,25 @@ QgsProviderRegistry::QgsProviderRegistry( QString pluginPath )
199199
} // QgsProviderRegistry ctor
200200

201201

202+
// typedef for the unload dataprovider function
203+
typedef void cleanupProviderFunction_t();
204+
202205
QgsProviderRegistry::~QgsProviderRegistry()
203206
{
207+
Providers::const_iterator it = mProviders.begin();
208+
209+
while ( it != mProviders.end() )
210+
{
211+
QString lib = it->second->library();
212+
QLibrary myLib( lib );
213+
if ( myLib.isLoaded() )
214+
{
215+
cleanupProviderFunction_t* cleanupFunc = ( cleanupProviderFunction_t* ) cast_to_fptr( myLib.resolve( "cleanupProvider" ) );
216+
if ( cleanupFunc )
217+
cleanupFunc();
218+
}
219+
it++;
220+
}
204221
}
205222

206223

@@ -292,7 +309,6 @@ QDir const & QgsProviderRegistry::libraryDirectory() const
292309
typedef QgsDataProvider * classFactoryFunction_t( const QString * );
293310

294311

295-
296312
/** Copied from QgsVectorLayer::setDataProvider
297313
* TODO: Make it work in the generic environment
298314
*

src/providers/gdal/qgsgdalprovider.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2767,3 +2767,8 @@ QGISEXTERN QList<QPair<QString, QString> > *pyramidResamplingMethods()
27672767

27682768
return &methods;
27692769
}
2770+
2771+
QGISEXTERN void cleanupProvider()
2772+
{
2773+
GDALDestroyDriverManager();
2774+
}

src/providers/ogr/qgsogrprovider.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2456,3 +2456,7 @@ QGISEXTERN QgsVectorLayerImport::ImportError createEmptyLayer(
24562456
);
24572457
}
24582458

2459+
QGISEXTERN void cleanupProvider()
2460+
{
2461+
OGRCleanupAll();
2462+
}

0 commit comments

Comments
 (0)