Skip to content

Commit

Permalink
delete contents in destructor and add missing mutexes
Browse files Browse the repository at this point in the history
  • Loading branch information
3nids committed May 7, 2018
1 parent 5610ebe commit b4d00d9
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 2 deletions.
2 changes: 2 additions & 0 deletions python/core/qgsnetworkcontentfetcherregistry.sip.in
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@ FetchedContent holds useful information about a network content being fetched
%Docstring
Constructs a FetchedContent with pointer to the downloaded file and status of the download
%End
~QgsFetchedContent();



const QString filePath() const;
Expand Down
5 changes: 3 additions & 2 deletions src/core/qgsnetworkcontentfetcherregistry.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,7 @@ QgsNetworkContentFetcherRegistry::~QgsNetworkContentFetcherRegistry()
QMap<QUrl, QgsFetchedContent *>::const_iterator it = mFileRegistry.constBegin();
for ( ; it != mFileRegistry.constEnd(); ++it )
{
it.value()->mFile->close();
delete it.value()->mFile;
delete it.value();
}
mFileRegistry.clear();
}
Expand Down Expand Up @@ -136,6 +135,7 @@ const QFile *QgsNetworkContentFetcherRegistry::localFile( const QString &filePat

if ( !QUrl::fromUserInput( filePathOrUrl ).isLocalFile() )
{
QMutexLocker locker( &mMutex );
if ( mFileRegistry.contains( QUrl( path ) ) )
{
const QgsFetchedContent *content = mFileRegistry.value( QUrl( path ) );
Expand Down Expand Up @@ -166,6 +166,7 @@ QString QgsNetworkContentFetcherRegistry::localPath( const QString &filePathOrUr

if ( !QUrl::fromUserInput( filePathOrUrl ).isLocalFile() )
{
QMutexLocker locker( &mMutex );
if ( mFileRegistry.contains( QUrl( path ) ) )
{
const QgsFetchedContent *content = mFileRegistry.value( QUrl( path ) );
Expand Down
6 changes: 6 additions & 0 deletions src/core/qgsnetworkcontentfetcherregistry.h
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,12 @@ class CORE_EXPORT QgsFetchedContent : public QObject
explicit QgsFetchedContent( QTemporaryFile *file = nullptr, ContentStatus status = NotStarted )
: QObject(), mFile( file ), mStatus( status ) {}

~QgsFetchedContent()
{
mFile->close();
delete mFile;
}


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

0 comments on commit b4d00d9

Please sign in to comment.