Plug leaks

This commit is contained in:
uclaros 2025-02-05 18:53:47 +02:00 committed by Nyall Dawson
parent 0b53d223f3
commit b76cdb8017
4 changed files with 30 additions and 18 deletions

View File

@ -32,9 +32,11 @@
QgsStacController::~QgsStacController()
{
qDeleteAll( mReplies );
qDeleteAll( mFetchedStacObjects );
qDeleteAll( mFetchedItemCollections );
qDeleteAll( mFetchedCollections );
}
int QgsStacController::fetchStacObjectAsync( const QUrl &url )
{
QNetworkReply *reply = fetchAsync( url );
@ -391,8 +393,3 @@ QgsStacItem *QgsStacController::openLocalItem( const QString &fileName ) const
parser.setBaseUrl( fileName );
return parser.item();
}

View File

@ -202,6 +202,7 @@ void QgsStacItemItem::itemRequestFinished( int requestId, QString error )
}
else
{
delete object;
mIconName = QStringLiteral( "/mIconDelete.svg" );
mName = error;
}

View File

@ -484,18 +484,25 @@ QgsStacItemCollection *QgsStacParser::itemCollection()
{
QVector< QgsStacLink > links = parseLinks( mData.at( "links" ) );
QVector< QgsStacItem * > items;
std::vector< std::unique_ptr<QgsStacItem> > items;
items.reserve( static_cast<int>( mData.at( "features" ).size() ) );
for ( auto &item : mData.at( "features" ) )
{
QgsStacItem *i = parseItem( item );
std::unique_ptr<QgsStacItem> i( parseItem( item ) );
if ( i )
items.append( i );
items.emplace_back( i.release() );
}
const int numberMatched = mData.contains( "numberMatched" ) ? mData["numberMatched"].get<int>() : -1;
return new QgsStacItemCollection( items, links, numberMatched );
QVector< QgsStacItem *> rawItems;
rawItems.reserve( items.size() );
for ( std::unique_ptr<QgsStacItem> &i : items )
{
rawItems.append( i.release() );
}
return new QgsStacItemCollection( rawItems, links, numberMatched );
}
catch ( nlohmann::json::exception &ex )
{
@ -511,18 +518,25 @@ QgsStacCollections *QgsStacParser::collections()
{
QVector< QgsStacLink > links = parseLinks( mData.at( "links" ) );
QVector< QgsStacCollection * > cols;
std::vector< std::unique_ptr<QgsStacCollection> > cols;
cols.reserve( static_cast<int>( mData.at( "collections" ).size() ) );
for ( auto &col : mData.at( "collections" ) )
{
QgsStacCollection *c = parseCollection( col );
std::unique_ptr<QgsStacCollection> c( parseCollection( col ) );
if ( c )
cols.append( c );
cols.emplace_back( c.release() );
}
const int numberMatched = mData.contains( "numberMatched" ) ? mData["numberMatched"].get<int>() : -1;
return new QgsStacCollections( cols, links, numberMatched );
QVector< QgsStacCollection * > rawCols;
rawCols.reserve( cols.size() );
for ( std::unique_ptr<QgsStacCollection> &c : cols )
{
rawCols.append( c.release() );
}
return new QgsStacCollections( rawCols, links, numberMatched );
}
catch ( nlohmann::json::exception &ex )
{

View File

@ -277,8 +277,8 @@ void QgsStacSourceSelect::cmbConnections_currentTextChanged( const QString &text
void QgsStacSourceSelect::onStacObjectRequestFinished( int requestId, QString error )
{
QgsDebugMsgLevel( QStringLiteral( "Finished object request %1" ).arg( requestId ), 2 );
QgsStacObject *obj = mStac->takeStacObject( requestId );
QgsStacCatalog *cat = dynamic_cast<QgsStacCatalog *>( obj );
std::unique_ptr<QgsStacObject> obj( mStac->takeStacObject( requestId ) );
QgsStacCatalog *cat = dynamic_cast<QgsStacCatalog *>( obj.get() );
if ( !cat )
{
@ -321,7 +321,7 @@ void QgsStacSourceSelect::onStacObjectRequestFinished( int requestId, QString er
void QgsStacSourceSelect::onCollectionsRequestFinished( int requestId, QString error )
{
QgsDebugMsgLevel( QStringLiteral( "Finished collections request %1" ).arg( requestId ), 2 );
QgsStacCollections *cols = mStac->takeCollections( requestId );
std::unique_ptr<QgsStacCollections> cols( mStac->takeCollections( requestId ) );
if ( !cols )
{
@ -343,7 +343,7 @@ void QgsStacSourceSelect::onCollectionsRequestFinished( int requestId, QString e
void QgsStacSourceSelect::onItemCollectionRequestFinished( int requestId, QString error )
{
QgsDebugMsgLevel( QStringLiteral( "Finished item collection request %1" ).arg( requestId ), 2 );
QgsStacItemCollection *col = mStac->takeItemCollection( requestId );
std::unique_ptr<QgsStacItemCollection> col( mStac->takeItemCollection( requestId ) );
if ( !col )
{