From fc46f5d756629caf32029155e8bf41c75a46ba7b Mon Sep 17 00:00:00 2001 From: Jonathan Barnard Date: Wed, 21 Oct 2009 16:38:56 +0100 Subject: [PATCH] UnitProgramsList: Fix memory leaks. --- Functions/ProgramsList/UnitProgramsList.pas | 43 +++++++++++++++-------------- 1 file changed, 23 insertions(+), 20 deletions(-) diff --git a/Functions/ProgramsList/UnitProgramsList.pas b/Functions/ProgramsList/UnitProgramsList.pas index 3af2eec..a318755 100644 --- a/Functions/ProgramsList/UnitProgramsList.pas +++ b/Functions/ProgramsList/UnitProgramsList.pas @@ -36,7 +36,6 @@ type var PreFixList:array of Tstrings; - cfg: TXMLConfig; CdData:Tstrings; CdDataName:Tstrings; Data:array of DataStore; @@ -60,6 +59,7 @@ var FullPathWithName:string; loop:integer; PrefixInt:integer; + SaveConfig:TXMLConfig; begin PrefixInt := FindPrefixInt(PrefixName); @@ -75,14 +75,12 @@ begin {Delete the old file.} if FileExists(FullPathWithName) then DeleteFile(FullPathWithName); - - Cfg := TXMLConfig.Create(nil); - + SaveConfig := TXMLConfig.Create(nil); Try - Cfg.FileName := FullPathWithName; + SaveConfig.FileName := FullPathWithName; - cfg.SetValue('Version', 6); - cfg.SetValue('PrefixName', PrefixName); + SaveConfig.SetValue('Version', 6); + SaveConfig.SetValue('PrefixName', PrefixName); {The frist row is the header} for loop := 1 to (data[PrefixInt].Grid.Cols[DataNameCol].Count -1) do @@ -91,19 +89,21 @@ begin if data[PrefixInt].Grid.Cells[DataNameCol,loop] = '' then exit; {The items need to start at 0.} - cfg.SetValue('Item' + InttoStr(loop - 1) + '/Name', data[PrefixInt].Grid.Cells[DataNameCol, loop]); - cfg.SetValue('Item' + InttoStr(loop - 1) + '/Path', data[PrefixInt].Grid.Cells[DataPathCol, loop]); + SaveConfig.SetValue('Item' + InttoStr(loop - 1) + '/Name', data[PrefixInt].Grid.Cells[DataNameCol, loop]); + SaveConfig.SetValue('Item' + InttoStr(loop - 1) + '/Path', data[PrefixInt].Grid.Cells[DataPathCol, loop]); if data[PrefixInt].Grid.Cells[DataFlagsCol, loop] <> '' then begin - cfg.SetValue('Item' + InttoStr(loop - 1) + '/Flags', data[PrefixInt].Grid.Cells[DataFlagsCol,loop] ); + SaveConfig.SetValue('Item' + InttoStr(loop - 1) + '/Flags', data[PrefixInt].Grid.Cells[DataFlagsCol,loop] ); end; end; Finally - Cfg.Flush; + SaveConfig.Flush; + SaveConfig.Free; end; + end; function ProgramsListLoadPrefix(PrefixName:string):boolean; @@ -113,6 +113,7 @@ var LoopCount:integer; Done:boolean; PrefixInt:integer; + LoadConfig:TXMLConfig; begin PrefixInt := FindPrefixInt(PrefixName); @@ -124,30 +125,31 @@ begin FullPathWithName := (PathWithName + '/' + PrefixDataName); + LoadConfig := TXMLConfig.Create(nil); + if FileExists(FullPathWithName) = true then begin - Cfg := TXMLConfig.Create(nil); Try - Cfg.FileName := FullPathWithName; + LoadConfig.FileName := FullPathWithName; {The items start at 0.} LoopCount := 0; Done := false; - if cfg.getValue('Version', -1) = 6 then + if LoadConfig.getValue('Version', -1) = 6 then begin while Done = false do begin {Do not load blank items.} - if cfg.GetValue('Item' + InttoStr(LoopCount) + '/Name', '') <> '' then + if LoadConfig.GetValue('Item' + InttoStr(LoopCount) + '/Name', '') <> '' then begin {Leave room for the header.} - data[PrefixInt].Grid.Cells[DataNameCol, LoopCount +1] := cfg.GetValue('Item' + InttoStr(LoopCount) + '/Name', ''); - data[PrefixInt].Grid.Cells[DataPathCol, LoopCount +1] := cfg.GetValue('Item' + InttoStr(LoopCount) + '/Path', ''); + data[PrefixInt].Grid.Cells[DataNameCol, LoopCount +1] := LoadConfig.GetValue('Item' + InttoStr(LoopCount) + '/Name', ''); + data[PrefixInt].Grid.Cells[DataPathCol, LoopCount +1] := LoadConfig.GetValue('Item' + InttoStr(LoopCount) + '/Path', ''); - if cfg.GetValue('Item' + InttoStr(LoopCount) + '/Flags', '') <> '' then + if LoadConfig.GetValue('Item' + InttoStr(LoopCount) + '/Flags', '') <> '' then begin - data[PrefixInt].Grid.Cells[DataFlagsCol, LoopCount +1] := cfg.GetValue('Item' + InttoStr(LoopCount) + '/Flags', ''); + data[PrefixInt].Grid.Cells[DataFlagsCol, LoopCount +1] := LoadConfig.GetValue('Item' + InttoStr(LoopCount) + '/Flags', ''); end; inc(LoopCount); end @@ -159,7 +161,8 @@ begin end; Finally - Cfg.Flush; + LoadConfig.Flush; + LoadConfig.Free; end; end; end; -- 2.11.4.GIT