* fixed all known memory leaks in the code added for the JVM port

git-svn-id: branches/jvmbackend@19248 -
This commit is contained in:
Jonas Maebe 2011-09-26 19:31:34 +00:00
parent 1edaa922c1
commit cf47b8d422
9 changed files with 52 additions and 17 deletions

View File

@ -682,6 +682,7 @@ interface
constructor Create(_stackslot: longint; const _desc: shortstring; _startlab, _stoplab: TAsmSymbol);
constructor ppuload(t:taitype;ppufile:tcompilerppufile);override;
procedure ppuwrite(ppufile:tcompilerppufile);override;
destructor destroy;override;
end;
tai_jvar_class = class of tai_jvar;
@ -691,6 +692,7 @@ interface
startlab,stoplab,handlerlab: tasmsymbol;
constructor Create(const _name: shortstring; _startlab, _stoplab, _handlerlab: TAsmSymbol);
destructor destroy;override;
constructor ppuload(t:taitype;ppufile:tcompilerppufile);override;
procedure ppuwrite(ppufile:tcompilerppufile);override;
end;
@ -2520,6 +2522,13 @@ implementation
end;
destructor tai_jvar.destroy;
begin
stringdispose(desc);
inherited destroy;
end;
{****************************************************************************
tai_jvar
****************************************************************************}
@ -2538,6 +2547,13 @@ implementation
end;
destructor tai_jcatch.destroy;
begin
stringdispose(name);
inherited destroy;
end;
constructor tai_jcatch.ppuload(t: taitype; ppufile: tcompilerppufile);
begin
inherited ppuload(t, ppufile);

View File

@ -286,9 +286,9 @@ implementation
hassinglerun: boolean;
begin
hassinglerun:=find_single_elements_run(0, start, len);
mp:=cloadvmtaddrnode.create(ctypenode.create(java_juenumset));
if hassinglerun then
begin
mp:=cloadvmtaddrnode.create(ctypenode.create(java_juenumset));
if len=0 then
begin
enumele:=cloadvmtaddrnode.create(ctypenode.create(tenumdef(eledef).getbasedef.classdef));

View File

@ -719,7 +719,6 @@ implementation
case csym.constdef.typ of
enumdef:
begin
replace_scanner('jvm_enum_const',sstate);
{ make sure we don't emit a definition for this field (we'll do
that for the constsym already) -> mark as external }
ssym:=tstaticvarsym.create(internal_static_field_name(csym.realname),vs_final,csym.constdef,[vo_is_external]);
@ -740,6 +739,7 @@ implementation
MessagePos(csym.fileinfo,parser_e_range_check_error);
exit;
end;
replace_scanner('jvm_enum_const',sstate);
str_parse_typedconst(current_asmdata.asmlists[al_typedconsts],esym.name+';',ssym);
restore_scanner(sstate);
result:=ssym;
@ -839,6 +839,7 @@ implementation
ps: tprocsym;
pvs: tparavarsym;
pd: tprocdef;
tmpaccesslist: tpropaccesslist;
callthroughpropname,
name: string;
callthroughprop: tpropertysym;
@ -870,9 +871,11 @@ implementation
callthroughprop.default:=longint($80000000);
if sp_static in p.symoptions then
include(callthroughprop.symoptions, sp_static);
{ copy original property target to callthrough property }
{ copy original property target to callthrough property (and replace
original one with the new empty list; will be filled in later) }
tmpaccesslist:=callthroughprop.propaccesslist[accesstyp];
callthroughprop.propaccesslist[accesstyp]:=p.propaccesslist[accesstyp];
p.propaccesslist[accesstyp]:=tpropaccesslist.create;
p.propaccesslist[accesstyp]:=tmpaccesslist;
p.owner.insert(callthroughprop);
{ we can't use str_parse_method_dec here because the type of the field

View File

@ -1192,10 +1192,8 @@ implementation
destructor ttempdeletenode.destroy;
begin
if assigned(tempinfo^.withnode) then
begin
tempinfo^.withnode.free;
end;
tempinfo^.withnode.free;
tempinfo^.tempinitcode.free;
dispose(tempinfo);
end;

View File

@ -577,6 +577,8 @@ implementation
destructor tcallparanode.destroy;
begin
fparainit.free;
fparacopyback.free;
inherited destroy;
end;

View File

@ -131,7 +131,7 @@ interface
preproc_pattern : string;
preproc_token : ttoken;
constructor Create(const fn:string);
constructor Create(const fn:string; is_macro: boolean = false);
destructor Destroy;override;
{ File buffer things }
function openinputfile:boolean;
@ -1893,9 +1893,11 @@ In case not, the value returned can be arbitrary.
TSCANNERFILE
****************************************************************************}
constructor tscannerfile.create(const fn:string);
constructor tscannerfile.create(const fn:string; is_macro: boolean = false);
begin
inputfile:=do_openinputfile(fn);
if is_macro then
inputfile.is_macro:=true;
if assigned(current_module) then
current_module.sourcefiles.register_file(inputfile);
{ reset localinput }
@ -1945,6 +1947,8 @@ In case not, the value returned can be arbitrary.
popreplaystack;
if not inputfile.closed then
closeinputfile;
if inputfile.is_macro then
inputfile.free;
ignoredirectives.free;
end;

View File

@ -146,7 +146,7 @@ implementation
{ creating a new scanner resets the block type, while we want to continue
in the current one }
old_block_type:=block_type;
current_scanner:=tscannerfile.Create('_Macro_.'+tempname);
current_scanner:=tscannerfile.Create('_Macro_.'+tempname,true);
block_type:=old_block_type;
{ required for e.g. FpcDeepCopy record method (uses "out" parameter; field
names are escaped via &, so should not cause conflicts }
@ -178,6 +178,11 @@ implementation
oldparse_only:=parse_only;
parse_only:=true;
result:=false;
{ in case multiple strings are injected, make sure to always close the
previous macro inputfile to prevent memory leaks }
if assigned(current_scanner.inputfile) and
not(current_scanner.inputfile.closed) then
current_scanner.closeinputfile;
{ inject the string in the scanner }
str:=str+'end;';
current_scanner.substitutemacro('meth_head_macro',@str[1],length(str),current_scanner.line_no,current_scanner.inputfile.ref_index);
@ -198,6 +203,10 @@ implementation
if assigned(pd) then
result:=true;
parse_only:=oldparse_only;
{ remove the temporary macro input file again }
current_scanner.closeinputfile;
current_scanner.nextfile;
current_scanner.tempopeninputfile;
end;
@ -229,6 +238,10 @@ implementation
{ and parse it... }
read_proc(is_classdef,usefwpd);
parse_only:=oldparse_only;
{ remove the temporary macro input file again }
current_scanner.closeinputfile;
current_scanner.nextfile;
current_scanner.tempopeninputfile;
result:=true;
end;
@ -251,6 +264,10 @@ implementation
read_typed_const(list,ssym,ssym.owner.symtabletype in [recordsymtable,objectsymtable]);
parse_only:=old_parse_only;
block_type:=old_block_type;
{ remove the temporary macro input file again }
current_scanner.closeinputfile;
current_scanner.nextfile;
current_scanner.tempopeninputfile;
end;

View File

@ -3022,11 +3022,6 @@ implementation
objname:=stringdup(upper(n));
objrealname:=stringdup(n);
objectoptions:=[];
if assigned(current_module.namespace) then
begin
import_lib:=stringdup(current_module.namespace^);
replace(import_lib^,'.','/');
end;
end;
constructor tabstractrecorddef.ppuload(dt:tdeftyp;ppufile:tcompilerppufile);
@ -3742,7 +3737,6 @@ implementation
end;
tabstractprocdef(result).returndef:=returndef;
tabstractprocdef(result).returndefderef:=returndefderef;
tabstractprocdef(result).parast:=tparasymtable.create(tabstractprocdef(result),parast.symtablelevel);
pvs:=nil;
npvs:=nil;
for j:=0 to parast.symlist.count-1 do

View File

@ -1406,6 +1406,7 @@ implementation
{$ifndef symansistr}
stringdispose(cachedmangledname);
{$endif symansistr}
stringdispose(externalname);
inherited destroy;
end;