MG: fixed mem leak in JITForms

git-svn-id: trunk@3355 -
This commit is contained in:
lazarus 2002-09-16 17:05:01 +00:00
parent d3f24412e6
commit 837b1b4d6d
2 changed files with 45 additions and 3 deletions

View File

@ -522,18 +522,48 @@ begin
end;
procedure TJITForms.FreevmtCopy(vmtCopy:Pointer);
var MethodTable : PMethodNameTable;
procedure FreeNewMethods(MethodTable: PMethodNameTable);
var
CurCount, BaseCount, i: integer;
BaseMethodTable: PMethodNameTable;
CurMethod: TMethodNameRec;
begin
if MethodTable=nil then exit;
BaseMethodTable:=PMethodNameTable((Pointer(TJITForm)+vmtMethodTable)^);
if Assigned(BaseMethodTable) then
BaseCount:=BaseMethodTable^.Count
else
BaseCount:=0;
CurCount:=MethodTable^.Count;
if CurCount=BaseCount then exit;
i:=CurCount;
while i>BaseCount do begin
CurMethod:=MethodTable^.Entries[i-1];
if CurMethod.Name<>nil then
FreeMem(CurMethod.Name);
if CurMethod.Addr<>nil then
FreeMem(CurMethod.Addr);
dec(i);
end;
end;
var
MethodTable : PMethodNameTable;
ClassNamePtr: Pointer;
begin
//writeln('[TJITForms.FreevmtCopy] ClassName='''+TClass(vmtCopy).ClassName+'''');
if vmtCopy=nil then exit;
// free copy of methodtable
MethodTable:=PMethodNameTable((Pointer(vmtCopy)+vmtMethodTable)^);
if (Assigned(MethodTable)) then
if (Assigned(MethodTable)) then begin
FreeNewMethods(MethodTable);
FreeMem(MethodTable);
end;
// free pointer to classname
ClassNamePtr:=Pointer(vmtCopy)+vmtClassName;
FreeMem(Pointer(ClassNamePtr^));
// free copy of VMT
FreeMem(vmtCopy);
end;

View File

@ -631,13 +631,25 @@ end;
Procedure TCustomFormEditor.DeleteControl(Value : TComponent);
var
Temp : TComponentInterface;
i: integer;
AForm: TCustomForm;
Begin
Temp := TComponentInterface(FindComponent(Value));
if Temp <> nil then
begin
RemoveFromComponentInterfaceList(Temp);
if (Value is TCustomForm) then begin
JITFormList.DestroyJITForm(TForm(Value));
AForm:=TCustomForm(Value);
i:=AForm.ComponentCount-1;
while i>=0 do begin
DeleteControl(AForm.Components[i]);
dec(i);
if i>AForm.ComponentCount-1 then
i:=AForm.ComponentCount-1;
end;
if not (AForm is TForm) then
writeln('WARNING: TCustomFormEditor.DeleteControl ',AForm.ClassName);
JITFormList.DestroyJITForm(TForm(AForm));
Temp.Destroy;
end
else