mirror of
https://gitlab.com/freepascal.org/lazarus/lazarus.git
synced 2025-08-17 15:59:13 +02:00
Jedi code format: Fix memory leak on unclosed quoted constant string.
This commit is contained in:
parent
d8a1016498
commit
5c65c6df5b
@ -102,7 +102,7 @@ type
|
|||||||
constructor Create;
|
constructor Create;
|
||||||
destructor Destroy; override;
|
destructor Destroy; override;
|
||||||
|
|
||||||
function BuildTokenList(AFlags:TBuildTokenListFlags=[]): TSourceTokenList;
|
procedure BuildTokenList(ASourceTokenList:TSourceTokenList;AFlags:TBuildTokenListFlags=[]);
|
||||||
|
|
||||||
property SourceCode: String read fsSourceCode write SetSourceCode;
|
property SourceCode: String read fsSourceCode write SetSourceCode;
|
||||||
property FileName: string read fsFileName write fsFileName;
|
property FileName: string read fsFileName write fsFileName;
|
||||||
@ -220,9 +220,13 @@ begin
|
|||||||
begin
|
begin
|
||||||
lcNewToken := TSourceToken.Create;
|
lcNewToken := TSourceToken.Create;
|
||||||
lcNewToken.FileName := FileName;
|
lcNewToken.FileName := FileName;
|
||||||
|
try
|
||||||
DoAllTheTries;
|
DoAllTheTries;
|
||||||
|
|
||||||
lcNewToken.WordType := WordTypeOfToken(lcNewToken.TokenType);
|
lcNewToken.WordType := WordTypeOfToken(lcNewToken.TokenType);
|
||||||
|
except
|
||||||
|
lcNewToken.Free;
|
||||||
|
raise;
|
||||||
|
end;
|
||||||
Result := lcNewToken;
|
Result := lcNewToken;
|
||||||
end;
|
end;
|
||||||
end;
|
end;
|
||||||
@ -534,7 +538,6 @@ begin
|
|||||||
end;
|
end;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
|
||||||
function TBuildTokenList.TryWord(const pcToken: TSourceToken): boolean;
|
function TBuildTokenList.TryWord(const pcToken: TSourceToken): boolean;
|
||||||
|
|
||||||
begin
|
begin
|
||||||
@ -958,37 +961,43 @@ begin
|
|||||||
end;
|
end;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
function TBuildTokenList.BuildTokenList(AFlags:TBuildTokenListFlags=[]): TSourceTokenList;
|
procedure TBuildTokenList.BuildTokenList(ASourceTokenList:TSourceTokenList;AFlags:TBuildTokenListFlags=[]);
|
||||||
const
|
const
|
||||||
UPDATE_INTERVAL = 4096; // big increments here, this goes faster than parsing
|
UPDATE_INTERVAL = 4096; // big increments here, this goes faster than parsing
|
||||||
var
|
var
|
||||||
lcList: TSourceTokenList;
|
|
||||||
lcNew: TSourceToken;
|
lcNew: TSourceToken;
|
||||||
liCounter: integer;
|
liCounter: integer;
|
||||||
lbIncludeToken: boolean;
|
lbIncludeToken: boolean;
|
||||||
begin
|
begin
|
||||||
Assert(SourceCode <> '');
|
Assert(SourceCode <> '');
|
||||||
liCounter := 0;
|
liCounter := 0;
|
||||||
lcList := TSourceTokenList.Create;
|
|
||||||
|
|
||||||
while not EndOfFile do
|
while not EndOfFile do
|
||||||
begin
|
begin
|
||||||
lbIncludeToken := True;
|
lbIncludeToken := True;
|
||||||
|
lcNew := nil;
|
||||||
|
try
|
||||||
lcNew := GetNextToken;
|
lcNew := GetNextToken;
|
||||||
|
if lcNew<>nil then
|
||||||
|
begin
|
||||||
if btlOnlyDirectives in AFlags then
|
if btlOnlyDirectives in AFlags then
|
||||||
begin
|
begin
|
||||||
if not ((lcNew.TokenType=ttComment) and (lcNew.CommentStyle=eCompilerDirective)) then
|
if not ((lcNew.TokenType=ttComment) and (lcNew.CommentStyle=eCompilerDirective)) then
|
||||||
lbIncludeToken := False;
|
lbIncludeToken := False;
|
||||||
end;
|
end;
|
||||||
if lbIncludeToken then
|
if lbIncludeToken then
|
||||||
lcList.Add(lcNew)
|
ASourceTokenList.Add(lcNew)
|
||||||
else
|
else
|
||||||
lcNew.Free;
|
lcNew.Free;
|
||||||
|
lcNew := nil;
|
||||||
|
end;
|
||||||
Inc(liCounter);
|
Inc(liCounter);
|
||||||
GetUI.UpdateGUI(liCounter, UPDATE_INTERVAL);
|
GetUI.UpdateGUI(liCounter, UPDATE_INTERVAL);
|
||||||
|
except
|
||||||
|
lcNew.Free;
|
||||||
|
raise;
|
||||||
|
end;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
Result := lcList;
|
|
||||||
end;
|
end;
|
||||||
|
|
||||||
function TBuildTokenList.Current: Char;
|
function TBuildTokenList.Current: Char;
|
||||||
|
@ -444,7 +444,8 @@ begin
|
|||||||
lcBTL := TBuildTokenList.Create;
|
lcBTL := TBuildTokenList.Create;
|
||||||
lcBTL.FileName := lsTemp;
|
lcBTL.FileName := lsTemp;
|
||||||
LcBTL.SourceCode := lsFileContentOrError;
|
LcBTL.SourceCode := lsFileContentOrError;
|
||||||
lcIncludedTokens := lcBTL.BuildTokenList([btlOnlyDirectives]);
|
lcIncludedTokens := TSourceTokenList.Create;
|
||||||
|
lcBTL.BuildTokenList(lcIncludedTokens,[btlOnlyDirectives]);
|
||||||
|
|
||||||
lPPT := TPreProcessorParseTree.Create(fcDefinedSymbols);
|
lPPT := TPreProcessorParseTree.Create(fcDefinedSymbols);
|
||||||
try
|
try
|
||||||
|
@ -163,7 +163,8 @@ begin
|
|||||||
// turn text into tokens
|
// turn text into tokens
|
||||||
fcTokeniser.SourceCode := InputCode;
|
fcTokeniser.SourceCode := InputCode;
|
||||||
fcTokeniser.FileName := FileName;
|
fcTokeniser.FileName := FileName;
|
||||||
lcTokenList := fcTokeniser.BuildTokenList;
|
lcTokenList := TSourceTokenList.Create;
|
||||||
|
fcTokeniser.BuildTokenList(lcTokenList);
|
||||||
try { finally free the list }
|
try { finally free the list }
|
||||||
try { show exceptions }
|
try { show exceptions }
|
||||||
fiTokenCount := lcTokenList.Count;
|
fiTokenCount := lcTokenList.Count;
|
||||||
@ -201,7 +202,7 @@ begin
|
|||||||
// should not be any tokens left
|
// should not be any tokens left
|
||||||
Assert(lcTokenList.Count = 0, 'Surplus tokens');
|
Assert(lcTokenList.Count = 0, 'Surplus tokens');
|
||||||
finally
|
finally
|
||||||
lcTokenList.Free;
|
FreeAndNil(lcTokenList);
|
||||||
end;
|
end;
|
||||||
|
|
||||||
try
|
try
|
||||||
@ -229,6 +230,12 @@ begin
|
|||||||
end;
|
end;
|
||||||
end;
|
end;
|
||||||
finally
|
finally
|
||||||
|
if lcTokenList<>nil then
|
||||||
|
begin
|
||||||
|
lcTokenList.OwnsObjects := True;
|
||||||
|
lcTokenList.Clear;
|
||||||
|
FreeAndNil(lcTokenList);
|
||||||
|
end;
|
||||||
GetUI.RestoreCursorUI;
|
GetUI.RestoreCursorUI;
|
||||||
end;
|
end;
|
||||||
end;
|
end;
|
||||||
|
Loading…
Reference in New Issue
Block a user