Browse Source

pas2js: fixed mem leak pcu

mattias 3 years ago
parent
commit
11e4f6285d
2 changed files with 10 additions and 1 deletions
  1. 6 0
      packages/fcl-passrc/src/pparser.pp
  2. 4 1
      packages/pastojs/src/pas2jsfiler.pp

+ 6 - 0
packages/fcl-passrc/src/pparser.pp

@@ -203,6 +203,7 @@ type
       virtual;
     function CreateFunctionType(const AName, AResultName: String; AParent: TPasElement;
       UseParentAsResultParent: Boolean; const ASrcPos: TPasSourcePos; TypeParams: TFPList = nil): TPasFunctionType;
+    procedure AddOwnedElement(El: TPasElement); virtual;
     function FindElement(const AName: String): TPasElement; virtual; abstract;
     function FindElementFor(const AName: String; AParent: TPasElement; TypeParamCount: integer): TPasElement; virtual;
     procedure BeginScope(ScopeType: TPasScopeType; El: TPasElement); virtual;
@@ -916,6 +917,11 @@ begin
                                     visDefault, ASrcPos, TypeParams));
 end;
 
+procedure TPasTreeContainer.AddOwnedElement(El: TPasElement);
+begin
+  FOwnedElements.Add(El);
+end;
+
 function TPasTreeContainer.FindElementFor(const AName: String;
   AParent: TPasElement; TypeParamCount: integer): TPasElement;
 begin

+ 4 - 1
packages/pastojs/src/pas2jsfiler.pp

@@ -5005,7 +5005,7 @@ begin
         {$IFDEF VerbosePCUFiler}
         writeln('TPCUWriter.WritePCU zip...');
         {$ENDIF}
-        Comp:=Tcompressionstream.create(cldefault,aStream);
+        Comp:=TCompressionStream.create(cldefault,aStream);
         try
           Comp.WriteDWord(TargetStream.Size);
           Comp.Write(TMemoryStream(TargetStream).Memory^,TargetStream.Size);
@@ -7232,6 +7232,9 @@ var
   Kind: TPasIdentifierKind;
 begin
   Result:=AClass.Create(AName,AParent);
+  {$IFDEF EnablePasTreeFree}
+  Resolver.AddOwnedElement(Result);
+  {$ENDIF}
   Result.SourceFilename:=SourceFilename;
   {$IFDEF CheckPasTreeRefCount}Result.RefIds.Add('CreateElement');{$ENDIF}
   if (AName<>'')