Explorar el Código

* set self to nil in current_module.deflist for registered defs in the
tstoreddef.destroy destructor, instead of doing it after each call to
x.owner.deletedef(x)

git-svn-id: trunk@49417 -

nickysn hace 4 años
padre
commit
ea5ffd597f
Se han modificado 4 ficheros con 6 adiciones y 15 borrados
  1. 0 5
      compiler/pdecvar.pas
  2. 0 5
      compiler/pmodules.pas
  3. 0 5
      compiler/pparautl.pas
  4. 6 0
      compiler/symdef.pas

+ 0 - 5
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;

+ 0 - 5
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 }

+ 0 - 5
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

+ 6 - 0
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<current_module.deflist.Count) and
+           (current_module.deflist[defid]=self) then
+          current_module.deflist[defid]:=nil;
         inherited destroy;
       end;