mirror of
				https://gitlab.com/freepascal.org/fpc/source.git
				synced 2025-10-31 01:11:29 +01:00 
			
		
		
		
	pastojs: fixed mem leaks
git-svn-id: trunk@39439 -
This commit is contained in:
		
							parent
							
								
									c7e07a792c
								
							
						
					
					
						commit
						b11c5943b0
					
				| @ -18545,7 +18545,6 @@ const | ||||
|     AssignSt.Expr:=FDS; | ||||
|     FD:=FDS.AFunction; | ||||
|     FD.Params.Add(EqualParamName); | ||||
|     FD.Body:=TJSFunctionBody(CreateElement(TJSFunctionBody,El)); | ||||
|     // add "return " | ||||
|     RetSt:=TJSReturnStatement(CreateElement(TJSReturnStatement,El)); | ||||
|     FD.Body.A:=RetSt; | ||||
|  | ||||
| @ -2097,6 +2097,7 @@ begin | ||||
|     l:=ms.Size-ms.Position; | ||||
|     if l>0 then | ||||
|     begin | ||||
|       s:=''; | ||||
|       SetLength(s,l); | ||||
|       ms.Read(s[1],l); | ||||
|     end | ||||
|  | ||||
| @ -563,6 +563,10 @@ type | ||||
|   end; | ||||
|   TPCUFilerElementRefArray = array of TPCUFilerElementRef; | ||||
| 
 | ||||
|   TPCUFilerElementRef2 = class(TPCUFilerElementRef) | ||||
|     s: string; | ||||
|   end; | ||||
| 
 | ||||
|   { TPCUFiler - base class TPCUWriter/TPCUReader} | ||||
| 
 | ||||
|   TPCUFiler = class | ||||
| @ -1822,10 +1826,18 @@ begin | ||||
| end; | ||||
| 
 | ||||
| function TPCUFiler.CreateElementRef(El: TPasElement): TPCUFilerElementRef; | ||||
| var | ||||
|   Node: TAVLTreeNode; | ||||
| begin | ||||
|   Result:=TPCUFilerElementRef.Create; | ||||
|   Result.Element:=El; | ||||
|   {$IFDEF MemCheck} | ||||
|   Node:=FElementRefs.Add(Result); | ||||
|   if Node<>FElementRefs.FindKey(El,@CompareElWithPCUFilerElementRef) then | ||||
|     RaiseMsg(20180711222046,El); | ||||
|   {$ELSE} | ||||
|   FElementRefs.Add(Result); | ||||
|   {$ENDIF} | ||||
| end; | ||||
| 
 | ||||
| procedure TPCUFiler.AddedBuiltInRef(Ref: TPCUFilerElementRef); | ||||
| @ -4063,6 +4075,7 @@ begin | ||||
|   if RefEl is TPasType then | ||||
|     begin | ||||
|     El.VarType:=TPasType(RefEl); | ||||
|     if RefEl.Parent<>El then | ||||
|       RefEl.AddRef; | ||||
|     end | ||||
|   else | ||||
| @ -4076,6 +4089,7 @@ begin | ||||
|   if RefEl is TPasType then | ||||
|     begin | ||||
|     El.DestType:=TPasType(RefEl); | ||||
|     if RefEl.Parent<>El then | ||||
|       RefEl.AddRef; | ||||
|     end | ||||
|   else | ||||
| @ -4090,6 +4104,7 @@ begin | ||||
|   if RefEl is TPasType then | ||||
|     begin | ||||
|     El.DestType:=TPasType(RefEl); | ||||
|     if RefEl.Parent<>El then | ||||
|       RefEl.AddRef; | ||||
|     end | ||||
|   else | ||||
| @ -4104,6 +4119,7 @@ begin | ||||
|   if RefEl is TPasType then | ||||
|     begin | ||||
|     El.DestType:=TPasType(RefEl); | ||||
|     if RefEl.Parent<>El then | ||||
|       RefEl.AddRef; | ||||
|     end | ||||
|   else | ||||
| @ -4117,6 +4133,7 @@ begin | ||||
|   if RefEl is TPasType then | ||||
|     begin | ||||
|     El.ElType:=TPasType(RefEl); | ||||
|     if RefEl.Parent<>El then | ||||
|       RefEl.AddRef; | ||||
|     end | ||||
|   else | ||||
| @ -4130,6 +4147,7 @@ begin | ||||
|   if RefEl is TPasType then | ||||
|     begin | ||||
|     El.ElType:=TPasType(RefEl); | ||||
|     if RefEl.Parent<>El then | ||||
|       RefEl.AddRef; | ||||
|     end | ||||
|   else | ||||
| @ -4143,6 +4161,7 @@ begin | ||||
|   if RefEl is TPasType then | ||||
|     begin | ||||
|     El.EnumType:=TPasType(RefEl); | ||||
|     if RefEl.Parent<>El then | ||||
|       RefEl.AddRef; | ||||
|     end | ||||
|   else | ||||
| @ -4156,6 +4175,7 @@ begin | ||||
|   if RefEl is TPasRecordType then | ||||
|     begin | ||||
|     El.Members:=TPasRecordType(RefEl); | ||||
|     if RefEl.Parent<>El then | ||||
|       RefEl.AddRef; | ||||
|     end | ||||
|   else | ||||
| @ -4170,6 +4190,7 @@ begin | ||||
|   if (RefEl is TPasType) or (RefEl.ClassType=TPasVariable) then | ||||
|     begin | ||||
|     El.VariantEl:=RefEl; | ||||
|     if RefEl.Parent<>El then | ||||
|       RefEl.AddRef; | ||||
|     end | ||||
|   else | ||||
| @ -4183,6 +4204,7 @@ begin | ||||
|   if RefEl is TPasType then | ||||
|     begin | ||||
|     El.ArgType:=TPasType(RefEl); | ||||
|     if RefEl.Parent<>El then | ||||
|       RefEl.AddRef; | ||||
|     end | ||||
|   else | ||||
| @ -4251,6 +4273,7 @@ begin | ||||
|   if RefEl is TPasType then | ||||
|     begin | ||||
|     El.AncestorType:=TPasType(RefEl); | ||||
|     if RefEl.Parent<>El then | ||||
|       RefEl.AddRef; | ||||
|     end | ||||
|   else | ||||
| @ -4265,6 +4288,7 @@ begin | ||||
|   if RefEl is TPasType then | ||||
|     begin | ||||
|     El.HelperForType:=TPasType(RefEl); | ||||
|     if RefEl.Parent<>El then | ||||
|       RefEl.AddRef; | ||||
|     end | ||||
|   else | ||||
| @ -4279,6 +4303,7 @@ begin | ||||
|   if RefEl is TPasType then | ||||
|     begin | ||||
|     El.ResultType:=TPasType(RefEl); | ||||
|     if RefEl.Parent<>El then | ||||
|       RefEl.AddRef; | ||||
|     end | ||||
|   else | ||||
| @ -4358,6 +4383,7 @@ begin | ||||
|     begin | ||||
|     Scope:=El.CustomData as TPasEnumTypeScope; | ||||
|     Scope.CanonicalSet:=TPasSetType(RefEl); | ||||
|     if RefEl.Parent<>El then | ||||
|       RefEl.AddRef; | ||||
|     end | ||||
|   else | ||||
| @ -4555,6 +4581,9 @@ var | ||||
|   RefItem: TPCUFilerPendingElRef; | ||||
|   PendingElRef: TPCUReaderPendingElRef; | ||||
|   PendingElListRef: TPCUReaderPendingElListRef; | ||||
|   {$IF defined(VerbosePCUFiler) or defined(memcheck)} | ||||
|   Node: TAVLTreeNode; | ||||
|   {$ENDIF} | ||||
| begin | ||||
|   if Id<=0 then | ||||
|     RaiseMsg(20180207151233,ErrorEl); | ||||
| @ -4580,18 +4609,30 @@ begin | ||||
|       end | ||||
|     else | ||||
|       begin | ||||
|       Ref:=TPCUFilerElementRef.Create; | ||||
|       Ref:=TPCUFilerElementRef2.Create; | ||||
|       TPCUFilerElementRef2(Ref).s:=IntToStr(Id); | ||||
|       Ref.Id:=Id; | ||||
|       end; | ||||
|     {$IF defined(VerbosePCUFiler) or defined(memcheck)} | ||||
|     if FElementRefsArray[Id]<>nil then | ||||
|       RaiseMsg(20180711212859,ErrorEl,IntToStr(Id)+' is not FElementRefsArray[Id]'); | ||||
|     {$ENDIF} | ||||
|     FElementRefsArray[Id]:=Ref; | ||||
|     end; | ||||
|   Result:=Ref; | ||||
| 
 | ||||
|   if El=nil then exit; | ||||
| 
 | ||||
|   if Ref.Element=nil then | ||||
|   if El=nil then | ||||
|     exit | ||||
|   else if Ref.Element=nil then | ||||
|     begin | ||||
|     Ref.Element:=El; | ||||
|     {$IF defined(VerbosePCUFiler) or defined(memcheck)} | ||||
|     Node:=FElementRefs.FindKey(El,@CompareElWithPCUFilerElementRef); | ||||
|     if Node<>nil then | ||||
|       RaiseMsg(20180711231646,El,GetObjName(TPCUFilerElementRef2(Node.Data).Element)); | ||||
|     {$ENDIF} | ||||
|     FElementRefs.Add(Ref); | ||||
| 
 | ||||
|     if Ref.Pending<>nil then | ||||
|       begin | ||||
|       // resolve pending references | ||||
| @ -7520,13 +7561,19 @@ end; | ||||
| 
 | ||||
| destructor TPCUReader.Destroy; | ||||
| begin | ||||
|   FreeAndNil(FJSON); | ||||
|   inherited Destroy; | ||||
|   FreeAndNil(FPendingIdentifierScopes); | ||||
|   FreeAndNil(FInitialFlags); | ||||
| end; | ||||
| 
 | ||||
| procedure TPCUReader.Clear; | ||||
| var | ||||
|   i: Integer; | ||||
| begin | ||||
|   for i:=0 to length(FElementRefsArray)-1 do | ||||
|     if (FElementRefsArray[i]<>nil) and (FElementRefsArray[i].Element=nil) then | ||||
|       FElementRefsArray[i].Free; | ||||
|   FElementRefsArray:=nil; | ||||
|   FPendingIdentifierScopes.Clear; | ||||
|   inherited Clear; | ||||
| @ -7543,6 +7590,7 @@ var | ||||
|   Count: Cardinal; | ||||
|   Src: TStream; | ||||
| begin | ||||
|   FirstBytes:=''; | ||||
|   SetLength(FirstBytes,4); | ||||
|   if aStream.Read(FirstBytes[1],4)<4 then | ||||
|     RaiseMsg(20180313232754,nil); | ||||
|  | ||||
		Loading…
	
		Reference in New Issue
	
	Block a user
	 Mattias Gaertner
						Mattias Gaertner