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