IDE: Create a list of custom key schemes as needed before making a first write to it. Fixes memory leak when calling ./lazarus --help.

This commit is contained in:
Maxim Ganetsky 2024-01-15 03:29:38 +03:00
parent 9700c1459b
commit 44a97af383
2 changed files with 12 additions and 3 deletions

View File

@ -4443,6 +4443,15 @@ begin
LoadCustomKeySchemasInDir(p, dir);
dir.Sort;
// Create CustomKeySchemas just before doing a first write to it in order
// to avoid memory leak when calling `./lazarus --help`.
if CustomKeySchemas = nil then
begin
// CustomKeySchemas should be freed in TMainIDE.Destroy destructor
CustomKeySchemas := TStringList.Create;
CustomKeySchemas.OwnsObjects := true;
end;
CustomKeySchemas.Clear;
CustomKeySchemas.Assign(dir);
finally
@ -4453,9 +4462,6 @@ end;
initialization
RegisterKeyCmdIdentProcs(@IdentToIDECommand,
@IDECommandToIdent);
// CustomKeySchemas should be freed in TMainIDE.Destroy destructor
CustomKeySchemas := TStringList.Create;
CustomKeySchemas.OwnsObjects := true;
emcIdeMouseCommandOffset := AllocatePluginMouseRange(emcIdeMouseCommandsCount);
RegisterMouseCmdIdentProcs(@IdentToIDEMouseCommand,

View File

@ -1223,7 +1223,10 @@
<Unit>
<Filename Value="keymapschemedlg.pas"/>
<IsPartOfProject Value="True"/>
<ComponentName Value="ChooseKeySchemeDlg"/>
<HasResources Value="True"/>
<ResourceBaseClass Value="Form"/>
<UnitName Value="KeymapSchemeDlg"/>
</Unit>
<Unit>
<Filename Value="gotofrm.pas"/>