diff --git a/compiler/pdecvar.pas b/compiler/pdecvar.pas index 446542e519..9e8e61cc81 100644 --- a/compiler/pdecvar.pas +++ b/compiler/pdecvar.pas @@ -1651,7 +1651,6 @@ implementation is_first_type: boolean; {$endif powerpc or powerpc64} old_block_type: tblock_type; - tmpidx: Integer; begin old_block_type:=block_type; block_type:=bt_var; @@ -2022,10 +2021,6 @@ implementation trecordsymtable(recst).insertunionst(Unionsymtable,offset); uniondef.owner.deletedef(uniondef); - { this prevents a dangling pointer and use after free } - tmpidx:=current_module.deflist.IndexOfItem(uniondef,FromEnd); - if tmpidx<>-1 then - current_module.deflist[tmpidx]:=nil; end; { free the list } sc.free; diff --git a/compiler/pmodules.pas b/compiler/pmodules.pas index 9094500eb5..d5037f7d60 100644 --- a/compiler/pmodules.pas +++ b/compiler/pmodules.pas @@ -614,7 +614,6 @@ implementation i: longint; def: tdef; sym: tsym; - tmpidx: Integer; begin for i:=current_module.localsymtable.deflist.count-1 downto 0 do begin @@ -634,10 +633,6 @@ implementation tprocdef(def).procsym.is_registered then tprocsym(tprocdef(def).procsym).ProcdefList.Remove(def); current_module.localsymtable.deletedef(def); - { this prevents a dangling pointer and use after free } - tmpidx:=current_module.deflist.IndexOfItem(def,FromEnd); - if tmpidx<>-1 then - current_module.deflist[tmpidx]:=nil; end; end; { from high to low so we hopefully have moves of less data } diff --git a/compiler/pparautl.pas b/compiler/pparautl.pas index b139cd785d..4608decce3 100644 --- a/compiler/pparautl.pas +++ b/compiler/pparautl.pas @@ -780,7 +780,6 @@ implementation forwardfound : boolean; symentry: TSymEntry; item : tlinkedlistitem; - tmpidx: Integer; begin forwardfound:=false; @@ -1093,10 +1092,6 @@ implementation { Release current procdef } currpd.owner.deletedef(currpd); - { this prevents a dangling pointer and use after free } - tmpidx:=current_module.deflist.IndexOfItem(currpd,FromEnd); - if tmpidx<>-1 then - current_module.deflist[tmpidx]:=nil; currpd:=fwpd; end else diff --git a/compiler/symdef.pas b/compiler/symdef.pas index fca90803bf..3e60580d37 100644 --- a/compiler/symdef.pas +++ b/compiler/symdef.pas @@ -1987,6 +1987,12 @@ implementation {$ifndef symansistr} stringdispose(_fullownerhierarchyname); {$endif not symansistr} + { set self to nil in current_module's deflist, if the def has been + registered, in order to avoid dangling pointers in current_module.deflist } + if registered and assigned(current_module) and + (defid>=0) and (defid