Ver Fonte

* fixed memleak for initfinalcode
* exit from generatecode when there are already errors

peter há 22 anos atrás
pai
commit
276688dbb4
2 ficheiros alterados com 23 adições e 12 exclusões
  1. 11 6
      compiler/pmodules.pas
  2. 12 6
      compiler/psub.pas

+ 11 - 6
compiler/pmodules.pas

@@ -805,7 +805,6 @@ implementation
          initfinalcode : taasmoutput;
          pd : tprocdef;
       begin
-         initfinalcode:=taasmoutput.create;
          consume(_UNIT);
          if compile_level=1 then
           Status.IsExe:=false;
@@ -1017,8 +1016,10 @@ implementation
          { this is a hack, but how can it be done better ? }
          if force_init_final and ((current_module.flags and uf_init)=0) then
            begin
+              initfinalcode:=taasmoutput.create;
               gen_implicit_initfinal(initfinalcode,uf_init,st);
               codesegment.concatlist(initfinalcode);
+              initfinalcode.free;
            end;
          { finalize? }
          if token=_FINALIZATION then
@@ -1036,8 +1037,10 @@ implementation
            end
          else if force_init_final then
            begin
+              initfinalcode:=taasmoutput.create;
               gen_implicit_initfinal(initfinalcode,uf_finalize,st);
               codesegment.concatlist(initfinalcode);
+              initfinalcode.free;
            end;
 
          { the last char should always be a point }
@@ -1176,8 +1179,6 @@ implementation
             exit;
           end;
 
-        initfinalcode.free;
-
         Message1(unit_u_finished_compiling,current_module.modulename^);
       end;
 
@@ -1190,7 +1191,6 @@ implementation
          initfinalcode : taasmoutput;
          pd : tprocdef;
       begin
-        initfinalcode:=taasmoutput.create;
          DLLsource:=islibrary;
          Status.IsLibrary:=IsLibrary;
          Status.IsExe:=true;
@@ -1317,12 +1317,14 @@ implementation
          { should we force unit initialization? }
          if tstaticsymtable(current_module.localsymtable).needs_init_final then
            begin
+              initfinalcode:=taasmoutput.create;
               { initialize section }
               gen_implicit_initfinal(initfinalcode,uf_init,st);
               codesegment.concatlist(initfinalcode);
               { finalize section }
               gen_implicit_initfinal(initfinalcode,uf_finalize,st);
               codesegment.concatlist(initfinalcode);
+              initfinalcode.free;
            end;
 
          { Add symbol to the exports section for win32 so smartlinking a
@@ -1437,13 +1439,16 @@ implementation
                 linker.MakeExecutable;
              end;
           end;
-         initfinalcode.free;
       end;
 
 end.
 {
   $Log$
-  Revision 1.128  2003-10-01 20:34:49  peter
+  Revision 1.129  2003-10-21 15:14:33  peter
+    * fixed memleak for initfinalcode
+    * exit from generatecode when there are already errors
+
+  Revision 1.128  2003/10/01 20:34:49  peter
     * procinfo unit contains tprocinfo
     * cginfo renamed to cgbase
     * moved cgmessage to verbose

+ 12 - 6
compiler/psub.pas

@@ -602,6 +602,10 @@ implementation
         if not assigned(code) then
           exit;
 
+        { We need valid code }
+        if Errorcount<>0 then
+          exit;
+
         { The RA and Tempgen shall not be available yet }
         if assigned(tg) then
           internalerror(200309201);
@@ -920,11 +924,10 @@ implementation
              { the procedure is now defined }
              procdef.forwarddef:=false;
 
-             { add implicit entry and exit code }
-             add_entry_exit_code(code,entrypos,exitpos);
-
              if (Errorcount=0) then
                begin
+                 { add implicit entry and exit code }
+                 add_entry_exit_code(code,entrypos,exitpos);
                  { check if forwards are resolved }
                  tstoredsymtable(procdef.localst).check_forwards;
                  { check if all labels are used }
@@ -1145,8 +1148,7 @@ implementation
                      Message(parser_w_inlining_disabled);
                      current_procinfo.procdef.proccalloption:=pocall_default;
                    end;
-                 if status.errorcount=0 then
-                   do_generate_code(tcgprocinfo(current_procinfo));
+                 do_generate_code(tcgprocinfo(current_procinfo));
                end;
 
              { reset _FAIL as _SELF normal }
@@ -1277,7 +1279,11 @@ implementation
 end.
 {
   $Log$
-  Revision 1.165  2003-10-20 19:28:51  peter
+  Revision 1.166  2003-10-21 15:14:33  peter
+    * fixed memleak for initfinalcode
+    * exit from generatecode when there are already errors
+
+  Revision 1.165  2003/10/20 19:28:51  peter
     * disable inlining when nested procedures are found
 
   Revision 1.164  2003/10/19 01:34:30  florian