Skip to content

Commit

Permalink
Fix leak of python apis when api file not found
Browse files Browse the repository at this point in the history
  • Loading branch information
nyalldawson committed Jan 11, 2023
1 parent 9ed5afb commit ef26beb
Showing 1 changed file with 5 additions and 4 deletions.
9 changes: 5 additions & 4 deletions src/gui/codeeditors/qgscodeeditorpython.cpp
Expand Up @@ -116,7 +116,7 @@ void QgsCodeEditorPython::initializeLexer()
pyLexer->setColor( lexerColor( QgsCodeEditorColorScheme::ColorRole::TripleSingleQuote ), QsciLexerPython::TripleSingleQuotedString );
pyLexer->setColor( lexerColor( QgsCodeEditorColorScheme::ColorRole::TripleDoubleQuote ), QsciLexerPython::TripleDoubleQuotedString );

QsciAPIs *apis = new QsciAPIs( pyLexer );
std::unique_ptr< QsciAPIs > apis = std::make_unique< QsciAPIs >( pyLexer );

const QgsSettings settings;

Expand Down Expand Up @@ -146,7 +146,6 @@ void QgsCodeEditorPython::initializeLexer()
}
}
apis->prepare();
pyLexer->setAPIs( apis );
}
}
else if ( mAPISFilesList.length() == 1 && mAPISFilesList[0].right( 3 ) == QLatin1String( "pap" ) )
Expand All @@ -161,7 +160,7 @@ void QgsCodeEditorPython::initializeLexer()
}
else
{
for ( const QString &path : mAPISFilesList )
for ( const QString &path : std::as_const( mAPISFilesList ) )
{
if ( !QFileInfo::exists( path ) )
{
Expand All @@ -173,8 +172,10 @@ void QgsCodeEditorPython::initializeLexer()
}
}
apis->prepare();
pyLexer->setAPIs( apis );
}
if ( apis )
pyLexer->setAPIs( apis.release() );

setLexer( pyLexer );

const int threshold = settings.value( QStringLiteral( "pythonConsole/autoCompThreshold" ), 2 ).toInt();
Expand Down

0 comments on commit ef26beb

Please sign in to comment.