Skip to content

Commit

Permalink
Plug leaks
Browse files Browse the repository at this point in the history
  • Loading branch information
uclaros committed Feb 5, 2025
1 parent 0687c16 commit 6c2de9b
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 18 deletions.
9 changes: 3 additions & 6 deletions src/core/stac/qgsstaccontroller.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,11 @@
QgsStacController::~QgsStacController()
{
qDeleteAll( mReplies );
qDeleteAll( mFetchedStacObjects );
qDeleteAll( mFetchedItemCollections );
qDeleteAll( mFetchedCollections );
}


int QgsStacController::fetchStacObjectAsync( const QUrl &url )
{
QNetworkReply *reply = fetchAsync( url );
Expand Down Expand Up @@ -382,8 +384,3 @@ QgsStacItem *QgsStacController::openLocalItem( const QString &fileName ) const
parser.setBaseUrl( fileName );
return parser.item();
}





1 change: 1 addition & 0 deletions src/core/stac/qgsstacdataitems.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -202,6 +202,7 @@ void QgsStacItemItem::itemRequestFinished( int requestId, QString error )
}
else
{
delete object;
mIconName = QStringLiteral( "/mIconDelete.svg" );
mName = error;
}
Expand Down
30 changes: 22 additions & 8 deletions src/core/stac/qgsstacparser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 )
{
Expand All @@ -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 )
{
Expand Down
8 changes: 4 additions & 4 deletions src/gui/stac/qgsstacsourceselect.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -276,8 +276,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 )
{
Expand Down Expand Up @@ -311,7 +311,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 )
{
Expand All @@ -333,7 +333,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 )
{
Expand Down

0 comments on commit 6c2de9b

Please sign in to comment.