Skip to content

Commit b4d00d9

Browse files
committed
delete contents in destructor and add missing mutexes
1 parent 5610ebe commit b4d00d9

3 files changed

Lines changed: 11 additions & 2 deletions

File tree

‎python/core/qgsnetworkcontentfetcherregistry.sip.in‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,8 @@ FetchedContent holds useful information about a network content being fetched
3939
%Docstring
4040
Constructs a FetchedContent with pointer to the downloaded file and status of the download
4141
%End
42+
~QgsFetchedContent();
43+
4244

4345

4446
const QString filePath() const;

‎src/core/qgsnetworkcontentfetcherregistry.cpp‎

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,7 @@ QgsNetworkContentFetcherRegistry::~QgsNetworkContentFetcherRegistry()
3030
QMap<QUrl, QgsFetchedContent *>::const_iterator it = mFileRegistry.constBegin();
3131
for ( ; it != mFileRegistry.constEnd(); ++it )
3232
{
33-
it.value()->mFile->close();
34-
delete it.value()->mFile;
33+
delete it.value();
3534
}
3635
mFileRegistry.clear();
3736
}
@@ -136,6 +135,7 @@ const QFile *QgsNetworkContentFetcherRegistry::localFile( const QString &filePat
136135

137136
if ( !QUrl::fromUserInput( filePathOrUrl ).isLocalFile() )
138137
{
138+
QMutexLocker locker( &mMutex );
139139
if ( mFileRegistry.contains( QUrl( path ) ) )
140140
{
141141
const QgsFetchedContent *content = mFileRegistry.value( QUrl( path ) );
@@ -166,6 +166,7 @@ QString QgsNetworkContentFetcherRegistry::localPath( const QString &filePathOrUr
166166

167167
if ( !QUrl::fromUserInput( filePathOrUrl ).isLocalFile() )
168168
{
169+
QMutexLocker locker( &mMutex );
169170
if ( mFileRegistry.contains( QUrl( path ) ) )
170171
{
171172
const QgsFetchedContent *content = mFileRegistry.value( QUrl( path ) );

‎src/core/qgsnetworkcontentfetcherregistry.h‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,12 @@ class CORE_EXPORT QgsFetchedContent : public QObject
5757
explicit QgsFetchedContent( QTemporaryFile *file = nullptr, ContentStatus status = NotStarted )
5858
: QObject(), mFile( file ), mStatus( status ) {}
5959

60+
~QgsFetchedContent()
61+
{
62+
mFile->close();
63+
delete mFile;
64+
}
65+
6066

6167
#ifndef SIP_RUN
6268
//! Return a pointer to the local file, a null pointer if the file is not accessible yet.

0 commit comments

Comments
 (0)