* more memory leaks fixed. Fpdoc is now memsafe except for the fcl-passrc bits

git-svn-id: trunk@13807 -
This commit is contained in:
marco 2009-10-05 21:10:47 +00:00
parent 8438ec58f7
commit 04247a4840

View File

@ -67,6 +67,7 @@ type
FWriteStream: TStream; FWriteStream: TStream;
FBlockStream: TMemoryStream; FBlockStream: TMemoryStream;
ParentNode: TFIftiNode; ParentNode: TFIftiNode;
OwnsParentNode : boolean;
function AdjustedWord(AWord: String; out AOffset: Byte; AOldWord: String): String; function AdjustedWord(AWord: String; out AOffset: Byte; AOldWord: String): String;
procedure ChildIsFull(AWord: String; ANodeOffset: DWord); virtual; abstract; procedure ChildIsFull(AWord: String; ANodeOffset: DWord); virtual; abstract;
function GuessIfCanHold(AWord: String): Boolean; virtual; abstract; function GuessIfCanHold(AWord: String): Boolean; virtual; abstract;
@ -91,6 +92,7 @@ type
public public
procedure WriteToStream; procedure WriteToStream;
constructor Create(AStream: TStream; AWordList: TIndexedWordList); constructor Create(AStream: TStream; AWordList: TIndexedWordList);
destructor Destroy; override;
end; end;
{ TChmSearchReader } { TChmSearchReader }
@ -259,6 +261,7 @@ begin
FActiveLeafNode.Flush(False); // causes the unwritten parts of the tree to be written FActiveLeafNode.Flush(False); // causes the unwritten parts of the tree to be written
end; end;
procedure TChmSearchWriter.WriteHeader ( IsPlaceHolder: Boolean ) ; procedure TChmSearchWriter.WriteHeader ( IsPlaceHolder: Boolean ) ;
var var
TmpNode: TFIftiNode; TmpNode: TFIftiNode;
@ -344,6 +347,7 @@ begin
end; end;
procedure TChmSearchWriter.WriteAWord ( AWord: TIndexedWord ) ; procedure TChmSearchWriter.WriteAWord ( AWord: TIndexedWord ) ;
begin begin
if FActiveLeafNode = nil then if FActiveLeafNode = nil then
begin begin
@ -363,7 +367,6 @@ begin
TLeafNode(FActiveLeafNode).AddWord(AWord); TLeafNode(FActiveLeafNode).AddWord(AWord);
end; end;
procedure TChmSearchWriter.WriteToStream; procedure TChmSearchWriter.WriteToStream;
begin begin
WriteHeader(True); WriteHeader(True);
@ -376,9 +379,16 @@ constructor TChmSearchWriter.Create ( AStream: TStream;
begin begin
FStream := AStream; FStream := AStream;
FWordList := AWordList; FWordList := AWordList;
FActiveLeafNode:=NIL;
end; end;
destructor TChmSearchWriter.Destroy;
begin
freeandnil(FActiveLeafNode);
end;
{ TLeafNode } { TLeafNode }
function TFIftiNode.RemainingSpace: DWord; function TFIftiNode.RemainingSpace: DWord;
@ -391,11 +401,13 @@ begin
inherited Create; inherited Create;
FWriteStream := AStream; FWriteStream := AStream;
FBlockStream := TMemoryStream.Create; FBlockStream := TMemoryStream.Create;
OwnsParentNode :=false;
end; end;
destructor TFIftiNode.Destroy; destructor TFIftiNode.Destroy;
begin begin
FBlockStream.Free; FBlockStream.Free;
if OwnsParentNode then ParentNode.Free;
inherited Destroy; inherited Destroy;
end; end;
@ -486,8 +498,10 @@ begin
if NewBlockNeeded or ((NewBlockNeeded = False) and (ParentNode <> nil)) then if NewBlockNeeded or ((NewBlockNeeded = False) and (ParentNode <> nil)) then
begin begin
if ParentNode = nil then if ParentNode = nil then
ParentNode := TIndexNode.Create(FWriteStream); begin
ParentNode := TIndexNode.Create(FWriteStream);
OwnsParentNode:=True;
end;
ParentNode.ChildIsFull(FLastWord, FLastNodeStart); ParentNode.ChildIsFull(FLastWord, FLastNodeStart);
if (NewBlockNeeded = False) then if (NewBlockNeeded = False) then
ParentNode.Flush(False); ParentNode.Flush(False);
@ -675,7 +689,10 @@ begin
if NewBlockNeeded then if NewBlockNeeded then
begin begin
if ParentNode = nil then if ParentNode = nil then
ParentNode := TIndexNode.Create(FWriteStream); begin
ParentNode := TIndexNode.Create(FWriteStream);
OwnsParentNode:=True;
end;
end; end;
if ParentNode <> nil then if ParentNode <> nil then