Browse Source

compiler: set to nil after free

mattias 5 days ago
parent
commit
2c1ff71e8c

+ 1 - 0
compiler/dbgbase.pas

@@ -348,6 +348,7 @@ implementation
             looplist := deftowritelist;
           end;
         templist.free;
+        templist := nil;
       end;
 
 

+ 9 - 0
compiler/dbgdwarf.pas

@@ -471,6 +471,7 @@ implementation
     destructor TDirIndexItem.Destroy;
       begin
         FFiles.Free;
+        FFiles := nil;
         inherited Destroy;
       end;
 
@@ -1084,6 +1085,7 @@ implementation
         append_block1(DW_AT_frame_base,blocksize);
         current_asmdata.asmlists[al_dwarf_info].concatlist(templist);
         templist.free;
+        templist := nil;
       end;
 {$elseif defined(wasm)}
       var
@@ -1103,6 +1105,7 @@ implementation
               append_block1(DW_AT_frame_base,blocksize);
               current_asmdata.asmlists[al_dwarf_info].concatlist(templist);
               templist.free;
+              templist := nil;
             end;
       end;
 {$else}
@@ -1144,6 +1147,7 @@ implementation
         append_block1(DW_AT_segment,blocksize);
         current_asmdata.asmlists[al_dwarf_info].concatlist(templist);
         templist.free;
+        templist := nil;
       end;
 {$endif i8086}
 
@@ -2646,6 +2650,7 @@ implementation
 {$endif i8086}
 
         templist.free;
+        templist := nil;
 
         finish_entry;
       end;
@@ -3014,6 +3019,7 @@ implementation
                   appendsym_var_with_name_type_offset(list,tabstractnormalvarsym(tosym),symname(sym, false),tabstractvarsym(sym).vardef,offset,flags);
                 end;
               templist.free;
+              templist := nil;
               exit;
             end;
         end;
@@ -3033,6 +3039,7 @@ implementation
         append_labelentry_ref(DW_AT_type,def_dwarf_lab(sym.vardef));
 
         templist.free;
+        templist := nil;
 
         finish_entry;
       end;
@@ -3102,6 +3109,7 @@ implementation
         templist.concat(tai_symbol.createname(target_asm.labelprefix+'debug_line0',AT_METADATA,0,voidpointertype));
         current_asmdata.asmlists[al_start].insertlist(templist);
         templist.free;
+        templist := nil;
 
         { finalize line info if the unit doesn't contain any function/ }
         { procedure/init/final code                                    }
@@ -3226,6 +3234,7 @@ implementation
         linelist.concat(tai_symbol.createname(target_asm.labelprefix+'edebug_line0',AT_METADATA,0,voidpointertype));
 
         flist.free;
+        flist := nil;
       end;
 
 

+ 3 - 0
compiler/dbgstabs.pas

@@ -1177,6 +1177,7 @@ implementation
         current_asmdata.asmlists[al_procedures].insertlistbefore(def.procstarttai,templist);
 
         templist.free;
+        templist := nil;
         current_procdef:=prev_procdef;
       end;
 
@@ -1749,7 +1750,9 @@ implementation
         deftowritelist:=nil;
 
         stabsvarlist.free;
+        stabsvarlist := nil;
         stabstypelist.free;
+        stabstypelist := nil;
         current_filepos:=storefilepos;
       end;
 

+ 1 - 0
compiler/entfile.pas

@@ -609,6 +609,7 @@ begin
 {$endif}
      if fisfile then
        f.Free;
+       f := nil;
      mode:=0;
      closed:=true;
    end;

+ 1 - 0
compiler/export.pas

@@ -282,6 +282,7 @@ procedure DoneExport;
 begin
   if assigned(Exportlib) then
     Exportlib.free;
+    Exportlib := nil;
 end;
 
 

+ 1 - 0
compiler/expunix.pas

@@ -75,6 +75,7 @@ end;
 destructor texportlibunix.destroy;
 begin
   fexportedsymnames.free;
+  fexportedsymnames := nil;
   inherited destroy;
 end;
 

+ 2 - 1
compiler/finput.pas

@@ -500,6 +500,7 @@ uses
         fileclose:=false;
         try
           f.Free;
+          f := nil;
           fileclose:=true;
         except
         end;
@@ -526,7 +527,7 @@ uses
          ifile : SizeInt;
       begin
          for ifile:=0 to nfiles-1 do
-          files[ifile].free;
+          FreeAndNil(files[ifile]);
          FreeMem(files);
       end;
 

+ 55 - 6
compiler/fmodule.pas

@@ -463,6 +463,7 @@ implementation
            get:=p.data;
            m:=p.needlink;
            p.free;
+           p := nil;
          end;
       end;
 
@@ -483,6 +484,7 @@ implementation
           getusemask:=p.data;
           found:=(p.needlink and mask)<>0;
           p.free;
+          p := nil;
         until found;
       end;
 
@@ -694,25 +696,25 @@ implementation
           end;
         derefmap:=nil;
         if assigned(_exports) then
-         _exports.free;
+          freeandnil(_exports);
         if assigned(dllscannerinputlist) then
-         dllscannerinputlist.free;
+          freeandnil(dllscannerinputlist);
         if assigned(localnamespacelist) then
-         localnamespacelist.free;
+          freeandnil(localnamespacelist);
         if assigned(scanner) then
-         begin
+          begin
             { also update current_scanner if it was pointing
               to this module }
             if current_scanner=tscannerfile(scanner) then
               set_current_scanner(nil);
             freeandnil(scanner);
-
-         end;
+          end;
         if assigned(asmdata) then
           begin
             if current_asmdata=asmdata then
               current_asmdata:=nil;
              asmdata.free;
+             asmdata := nil;
           end;
         if assigned(procinfo) then
           begin
@@ -729,40 +731,68 @@ implementation
           end;
         DoneDebugInfo(self,current_debuginfo_reset);
         used_units.free;
+        used_units := nil;
         dependent_units.free;
+        dependent_units := nil;
         resourcefiles.Free;
+        resourcefiles := nil;
         linkorderedsymbols.Free;
+        linkorderedsymbols := nil;
         linkunitofiles.Free;
+        linkunitofiles := nil;
         linkunitstaticlibs.Free;
+        linkunitstaticlibs := nil;
         linkunitsharedlibs.Free;
+        linkunitsharedlibs := nil;
         linkotherofiles.Free;
+        linkotherofiles := nil;
         linkotherstaticlibs.Free;
+        linkotherstaticlibs := nil;
         linkothersharedlibs.Free;
+        linkothersharedlibs := nil;
         linkotherframeworks.Free;
+        linkotherframeworks := nil;
         stringdispose(mainname);
         externasmsyms.Free;
+        externasmsyms := nil;
         publicasmsyms.Free;
+        publicasmsyms := nil;
         unitimportsyms.Free;
+        unitimportsyms := nil;
         FImportLibraryList.Free;
+        FImportLibraryList := nil;
         extendeddefs.Free;
+        extendeddefs := nil;
         genericdummysyms.free;
+        genericdummysyms := nil;
         pendingspecializations.free;
+        pendingspecializations := nil;
         waitingforunit.free;
+        waitingforunit := nil;
         waitingunits.free;
+        waitingunits := nil;
         used_rtti_attrs.free;
+        used_rtti_attrs := nil;
         stringdispose(asmprefix);
         stringdispose(deprecatedmsg);
         stringdispose(namespace);
         tcinitcode.free;
+        tcinitcode := nil;
         localunitsearchpath.Free;
+        localunitsearchpath := nil;
         localobjectsearchpath.free;
+        localobjectsearchpath := nil;
         localincludesearchpath.free;
+        localincludesearchpath := nil;
         locallibrarysearchpath.free;
+        locallibrarysearchpath := nil;
         localframeworksearchpath.free;
+        localframeworksearchpath := nil;
 {$ifdef MEMDEBUG}
         memsymtable.start;
 {$endif}
         derefdata.free;
+        derefdata := nil;
         if assigned(deflist) then
           begin
             for i:=0 to deflist.Count-1 do
@@ -770,27 +800,45 @@ implementation
                  (tdef(deflist[i]).registered_in_module=self) then
                 tdef(deflist[i]).registered_in_module:=nil;
             deflist.free;
+            deflist := nil;
           end;
         symlist.free;
+        symlist := nil;
         ptrdefs.free;
+        ptrdefs := nil;
         arraydefs.free;
+        arraydefs := nil;
         procaddrdefs.free;
+        procaddrdefs := nil;
 {$ifdef llvm}
         llvmdefs.free;
+        llvmdefs := nil;
         llvmusedsyms.free;
+        llvmusedsyms := nil;
         llvmcompilerusedsyms.free;
+        llvmcompilerusedsyms := nil;
         llvminitprocs.free;
+        llvminitprocs := nil;
         llvmfiniprocs.free;
+        llvmfiniprocs := nil;
         llvmmetadatastrings.free;
+        llvmmetadatastrings := nil;
 {$endif llvm}
         ansistrdef:=nil;
         wpoinfo.free;
+        wpoinfo := nil;
         checkforwarddefs.free;
+        checkforwarddefs := nil;
         forwardgenericdefs.free;
+        forwardgenericdefs := nil;
         globalsymtable.free;
+        globalsymtable := nil;
         localsymtable.free;
+        localsymtable := nil;
         globalmacrosymtable.free;
+        globalmacrosymtable := nil;
         localmacrosymtable.free;
+        localmacrosymtable := nil;
 {$ifdef MEMDEBUG}
         memsymtable.stop;
 {$endif}
@@ -1457,6 +1505,7 @@ initialization
 finalization
 {$ifdef MEMDEBUG}
   memsymtable.free;
+  memsymtable := nil;
 {$endif MEMDEBUG}
 
 end.

+ 2 - 0
compiler/fpcp.pas

@@ -312,6 +312,7 @@ implementation
           rewriteppu(module^.module.ppufilename,stream);
           module^.size:=stream.position;
           stream.free;
+          stream := nil;
         end;
 
       pos:=pcpfile.position;
@@ -416,6 +417,7 @@ implementation
   destructor tpcppackage.destroy;
     begin
       pcpfile.free;
+      pcpfile := nil;
       inherited destroy;
     end;
 

+ 4 - 1
compiler/fpkg.pas

@@ -26,6 +26,7 @@ unit fpkg;
 interface
 
   uses
+    sysutils,
     cclasses,
     globtype,
     finput;
@@ -87,7 +88,9 @@ implementation
             dispose(p);
           end;
       containedmodules.free;
+      containedmodules := nil;
       requiredpackages.free;
+      requiredpackages := nil;
       inherited destroy;
     end;
 
@@ -108,7 +111,7 @@ implementation
             for i:=0 to packagelist.count-1 do
               begin
                 pkgentry:=ppackageentry(packagelist[i]);
-                pkgentry^.package.free;
+                FreeAndNil(pkgentry^.package);
                 dispose(pkgentry);
               end;
           end;

+ 1 - 0
compiler/fppu.pas

@@ -2530,6 +2530,7 @@ var
                       end;
                     finally
                       Cycle.Free;
+                      Cycle := nil;
                     end;
                     if assigned(hp2) then
                       Message2(unit_f_circular_unit_reference,callermodule.realmodulename^,hp.realmodulename^);