Browse Source

compiler: set to nil after free

mattias 6 days ago
parent
commit
98ab19b6eb

+ 1 - 0
compiler/blockutl.pas

@@ -373,6 +373,7 @@ implementation
         end;
         end;
 
 
       procvarnode.free;
       procvarnode.free;
+      procvarnode := nil;
 
 
       { restore scanner }
       { restore scanner }
       restore_scanner(sstate);
       restore_scanner(sstate);

+ 14 - 11
compiler/cclasses.pas

@@ -1059,7 +1059,7 @@ begin
     exit;
     exit;
   Lp := Lst.FList;
   Lp := Lst.FList;
   for I := 0 to Lst.Count-1 do
   for I := 0 to Lst.Count-1 do
-    TObject(Lp[I]).Free;
+    TObject(Lp[I]).Free; // no nil needed
   Lst.Free;
   Lst.Free;
   Lst := nil;
   Lst := nil;
 end;
 end;
@@ -1112,7 +1112,7 @@ var
 begin
 begin
   if FFreeObjects then
   if FFreeObjects then
     for i := 0 to FList.Count - 1 do
     for i := 0 to FList.Count - 1 do
-      TObject(FList[i]).Free;
+      TObject(FList[i]).Free; // no nil needed
   FList.Clear;
   FList.Clear;
 end;
 end;
 
 
@@ -1152,7 +1152,7 @@ end;
 procedure TFPObjectList.SetItem(Index: Integer; AObject: TObject);
 procedure TFPObjectList.SetItem(Index: Integer; AObject: TObject);
 begin
 begin
   if OwnsObjects then
   if OwnsObjects then
-    TObject(FList[Index]).Free;
+    TObject(FList[Index]).Free; // no nil needed
   FList[index] := AObject;
   FList[index] := AObject;
 end;
 end;
 
 
@@ -1174,7 +1174,7 @@ end;
 procedure TFPObjectList.Delete(Index: Integer);
 procedure TFPObjectList.Delete(Index: Integer);
 begin
 begin
   if OwnsObjects then
   if OwnsObjects then
-    TObject(FList[Index]).Free;
+    TObject(FList[Index]).Free; // no nil needed
   FList.Delete(Index);
   FList.Delete(Index);
 end;
 end;
 
 
@@ -1200,7 +1200,7 @@ begin
   if (Result <> -1) then
   if (Result <> -1) then
   begin
   begin
     if OwnsObjects then
     if OwnsObjects then
-      TObject(FList[Result]).Free;
+      TObject(FList[Result]).Free; // no nil needed
     FList.Delete(Result);
     FList.Delete(Result);
   end;
   end;
 end;
 end;
@@ -1893,7 +1893,7 @@ var
 begin
 begin
   if FFreeObjects then
   if FFreeObjects then
     for i := 0 to FHashList.Count - 1 do
     for i := 0 to FHashList.Count - 1 do
-      TObject(FHashList[i]).Free;
+      TObject(FHashList[i]).Free; // no nil needed
   FHashList.Clear;
   FHashList.Clear;
 end;
 end;
 
 
@@ -1921,7 +1921,7 @@ end;
 procedure TFPHashObjectList.SetItem(Index: Integer; AObject: TObject);
 procedure TFPHashObjectList.SetItem(Index: Integer; AObject: TObject);
 begin
 begin
   if OwnsObjects then
   if OwnsObjects then
-    TObject(FHashList[Index]).Free;
+    TObject(FHashList[Index]).Free; // no nil needed
   FHashList[index] := AObject;
   FHashList[index] := AObject;
 end;
 end;
 
 
@@ -1958,7 +1958,7 @@ end;
 procedure TFPHashObjectList.Delete(Index: Integer);
 procedure TFPHashObjectList.Delete(Index: Integer);
 begin
 begin
   if OwnsObjects then
   if OwnsObjects then
-    TObject(FHashList[Index]).Free;
+    TObject(FHashList[Index]).Free; // no nil needed
   FHashList.Delete(Index);
   FHashList.Delete(Index);
 end;
 end;
 
 
@@ -1979,7 +1979,7 @@ begin
   if (Result <> -1) then
   if (Result <> -1) then
     begin
     begin
       if OwnsObjects then
       if OwnsObjects then
-        TObject(FHashList[Result]).Free;
+        TObject(FHashList[Result]).Free; // no nil needed
       FHashList.Delete(Result);
       FHashList.Delete(Result);
     end;
     end;
 end;
 end;
@@ -2541,6 +2541,7 @@ end;
          begin
          begin
            inherited Remove(p);
            inherited Remove(p);
            p.Free;
            p.Free;
+           p := nil;
          end;
          end;
       end;
       end;
 
 
@@ -2556,6 +2557,7 @@ end;
           begin
           begin
             GetFirst:=p.FPStr;
             GetFirst:=p.FPStr;
             p.free;
             p.free;
+            p := nil;
           end;
           end;
       end;
       end;
 
 
@@ -2571,6 +2573,7 @@ end;
           begin
           begin
             Getlast:=p.FPStr;
             Getlast:=p.FPStr;
             p.free;
             p.free;
+            p := nil;
           end;
           end;
       end;
       end;
 
 
@@ -2985,7 +2988,7 @@ end;
           begin
           begin
             next := item^.Next;
             next := item^.Next;
             if FOwnsObjects then
             if FOwnsObjects then
-              item^.Data.Free;
+              FreeAndNil(item^.Data);
             FreeItem(item);
             FreeItem(item);
             item := next;
             item := next;
           end;
           end;
@@ -3136,7 +3139,7 @@ end;
               begin
               begin
                 chain^ := Entry^.Next;
                 chain^ := Entry^.Next;
                 if FOwnsObjects then
                 if FOwnsObjects then
-                  Entry^.Data.Free;
+                  FreeAndNil(Entry^.Data);
                 FreeItem(Entry);
                 FreeItem(Entry);
                 Dec(FCount);
                 Dec(FCount);
                 Result := True;
                 Result := True;

+ 1 - 0
compiler/cfidwarf.pas

@@ -271,6 +271,7 @@ implementation
     destructor TDwarfAsmCFILowLevel.destroy;
     destructor TDwarfAsmCFILowLevel.destroy;
       begin
       begin
         FDwarfList.Free;
         FDwarfList.Free;
+        FDwarfList := nil;
       end;
       end;
 
 
 
 

+ 4 - 0
compiler/cfileutl.pas

@@ -219,6 +219,7 @@ end;
       begin
       begin
         FreeDirectoryEntries;
         FreeDirectoryEntries;
         FDirectoryEntries.Free;
         FDirectoryEntries.Free;
+        FDirectoryEntries := nil;
         inherited destroy;
         inherited destroy;
       end;
       end;
 
 
@@ -390,6 +391,7 @@ end;
     destructor TDirectoryCache.destroy;
     destructor TDirectoryCache.destroy;
       begin
       begin
         FDirectories.Free;
         FDirectories.Free;
+        FDirectories := nil;
         inherited destroy;
         inherited destroy;
       end;
       end;
 
 
@@ -1116,6 +1118,7 @@ end;
              Insert(s);
              Insert(s);
            end;
            end;
           hl.Free;
           hl.Free;
+          hl := nil;
         end
         end
        else
        else
         begin
         begin
@@ -1556,6 +1559,7 @@ end;
     procedure DoneFileUtils;
     procedure DoneFileUtils;
       begin
       begin
         DirCache.Free;
         DirCache.Free;
+        DirCache := nil;
       end;
       end;
 
 
 end.
 end.

+ 2 - 0
compiler/cg64f32.pas

@@ -1008,6 +1008,7 @@ unit cg64f32;
 
 
              hlcg.g_rangecheck(list,temploc,hdef,todef);
              hlcg.g_rangecheck(list,temploc,hdef,todef);
              hdef.free;
              hdef.free;
+             hdef := nil;
 
 
              if from_signed and to_signed then
              if from_signed and to_signed then
                begin
                begin
@@ -1041,6 +1042,7 @@ unit cg64f32;
                  temploc.size:=OS_32;
                  temploc.size:=OS_32;
                  hlcg.g_rangecheck(list,temploc,hdef,todef);
                  hlcg.g_rangecheck(list,temploc,hdef,todef);
                  hdef.free;
                  hdef.free;
+                 hdef := nil;
                  cg.a_label(list,endlabel);
                  cg.a_label(list,endlabel);
                end;
                end;
            end
            end

+ 6 - 0
compiler/comprsrc.pas

@@ -244,6 +244,7 @@ destructor TWinLikeResourceFile.Destroy;
 begin
 begin
   if fResScript<>nil then
   if fResScript<>nil then
     fResScript.Free;
     fResScript.Free;
+    fResScript := nil;
   inherited;
   inherited;
 end;
 end;
 
 
@@ -450,7 +451,9 @@ begin
     end;
     end;
   dst.CopyFrom(src,src.Size);
   dst.CopyFrom(src,src.Size);
   dst.Free;
   dst.Free;
+  dst := nil;
   src.Free;
   src.Free;
+  src := nil;
   Result:=true;
   Result:=true;
 end;
 end;
  
  
@@ -486,6 +489,7 @@ begin
       if resourcefile.IsCompiled(s) then
       if resourcefile.IsCompiled(s) then
         begin
         begin
           resourcefile.free;
           resourcefile.free;
+          resourcefile := nil;
           if AnsiCompareFileName(IncludeTrailingPathDelimiter(ExpandFileName(current_module.outputpath)), p) <> 0 then
           if AnsiCompareFileName(IncludeTrailingPathDelimiter(ExpandFileName(current_module.outputpath)), p) <> 0 then
             begin
             begin
               { Copy .res file to units output dir. Otherwise .res file will not be found
               { Copy .res file to units output dir. Otherwise .res file will not be found
@@ -510,6 +514,7 @@ begin
             end;
             end;
           resourcefile.compile(outfmt, current_module.outputpath+res.FPStr);
           resourcefile.compile(outfmt, current_module.outputpath+res.FPStr);
           resourcefile.free;
           resourcefile.free;
+          resourcefile := nil;
         end;
         end;
       res:=TCmdStrListItem(res.Next);
       res:=TCmdStrListItem(res.Next);
     end;
     end;
@@ -564,6 +569,7 @@ begin
   { Finish collection }
   { Finish collection }
   resourcefile.EndCollect;
   resourcefile.EndCollect;
   resourcefile.free;
   resourcefile.free;
+  resourcefile := nil;
 end;
 end;
 
 
 procedure initglobals;
 procedure initglobals;

+ 1 - 1
compiler/cprofile.pas

@@ -106,7 +106,7 @@ finalization
   for t:=low(timers) to high(timers) do
   for t:=low(timers) to high(timers) do
     writeln(StdErr,'  ',t,' ',timers[t].Elapsed:0:9,' s');
     writeln(StdErr,'  ',t,' ',timers[t].Elapsed:0:9,' s');
   for t:=low(timers) to high(timers) do
   for t:=low(timers) to high(timers) do
-    timers[t].Free;
+    FreeAndNil(timers[t]);
 {$endif COMPILER_TIMINGS}
 {$endif COMPILER_TIMINGS}
 end.
 end.
 
 

+ 4 - 0
compiler/cresstr.pas

@@ -161,6 +161,7 @@ uses
     Destructor Tresourcestrings.Destroy;
     Destructor Tresourcestrings.Destroy;
       begin
       begin
         List.Free;
         List.Free;
+        List := nil;
       end;
       end;
 
 
 
 
@@ -235,6 +236,7 @@ uses
             );
             );
             R:=TResourceStringItem(R.Next);
             R:=TResourceStringItem(R.Next);
             tcb.free;
             tcb.free;
+            tcb := nil;
           end;
           end;
         tcb:=ctai_typedconstbuilder.create([tcalo_vectorized_dead_strip_end,tcalo_data_force_indirect,tcalo_is_public_asm]);
         tcb:=ctai_typedconstbuilder.create([tcalo_vectorized_dead_strip_end,tcalo_data_force_indirect,tcalo_is_public_asm]);
         tcb.begin_anonymous_record(internaltypeprefixName[itp_emptyrec],
         tcb.begin_anonymous_record(internaltypeprefixName[itp_emptyrec],
@@ -246,6 +248,7 @@ uses
           )
           )
         );
         );
         tcb.free;
         tcb.free;
+        tcb := nil;
       end;
       end;
 
 
     procedure Tresourcestrings.WriteRSJFile;
     procedure Tresourcestrings.WriteRSJFile;
@@ -368,6 +371,7 @@ uses
             resstrs.WriteRSJFile;
             resstrs.WriteRSJFile;
           end;
           end;
         resstrs.Free;
         resstrs.Free;
+        resstrs := nil;
         symtablestack.pop(current_module.localsymtable);
         symtablestack.pop(current_module.localsymtable);
         if assigned(current_module.globalsymtable) then
         if assigned(current_module.globalsymtable) then
           symtablestack.pop(current_module.globalsymtable);
           symtablestack.pop(current_module.globalsymtable);

+ 1 - 0
compiler/cscript.pas

@@ -156,6 +156,7 @@ end;
 destructor TScript.Destroy;
 destructor TScript.Destroy;
 begin
 begin
   data.Free;
   data.Free;
+  data := nil;
 end;
 end;
 
 
 
 

+ 2 - 0
compiler/cstreams.pas

@@ -623,6 +623,7 @@ begin
     SaveToStream(S);
     SaveToStream(S);
   finally
   finally
     S.free;
     S.free;
+    S := nil;
   end;
   end;
 end;
 end;
 
 
@@ -711,6 +712,7 @@ begin
     LoadFromStream(S);
     LoadFromStream(S);
   finally
   finally
     S.free;
     S.free;
+    S := nil;
   end;
   end;
 end;
 end;
 
 

+ 1 - 0
compiler/ctask.pas

@@ -164,6 +164,7 @@ end;
 destructor ttask_handler.destroy;
 destructor ttask_handler.destroy;
 begin
 begin
   hash.free;
   hash.free;
+  hash := nil;
   List.Clear;
   List.Clear;
   FreeAndNil(list);
   FreeAndNil(list);
   inherited destroy;
   inherited destroy;