Ver código fonte

* fixed memleaks when file can't be opened

peter 23 anos atrás
pai
commit
5ea6f2b824
3 arquivos alterados com 29 adições e 9 exclusões
  1. 12 6
      compiler/parser.pas
  2. 6 1
      compiler/pdecvar.pas
  3. 11 2
      compiler/scanner.pas

+ 12 - 6
compiler/parser.pas

@@ -279,7 +279,6 @@ implementation
 {         implementation, so doesn't need to be saved/restored (JM) }
 {         implementation, so doesn't need to be saved/restored (JM) }
 {          oldexceptblockcounter  : integer;                        }
 {          oldexceptblockcounter  : integer;                        }
          oldstatement_level : integer;
          oldstatement_level : integer;
-         prev_name          : pstring;
 {$ifdef USEEXCEPT}
 {$ifdef USEEXCEPT}
 {$ifndef Delphi}
 {$ifndef Delphi}
          recoverpos    : jmp_buf;
          recoverpos    : jmp_buf;
@@ -295,7 +294,6 @@ implementation
 
 
       begin
       begin
          inc(compile_level);
          inc(compile_level);
-         prev_name:=stringdup(parser_current_file);
          parser_current_file:=filename;
          parser_current_file:=filename;
          old_compiled_module:=compiled_module;
          old_compiled_module:=compiled_module;
        { save symtable state }
        { save symtable state }
@@ -416,8 +414,9 @@ implementation
          aktasmmode:=initasmmode;
          aktasmmode:=initasmmode;
          aktinterfacetype:=initinterfacetype;
          aktinterfacetype:=initinterfacetype;
 
 
-       { startup scanner, and save in current_module }
+       { startup scanner and load the first file }
          current_scanner:=tscannerfile.Create(filename);
          current_scanner:=tscannerfile.Create(filename);
+         current_scanner.firstfile;
        { macros }
        { macros }
          default_macros;
          default_macros;
        { read the first token }
        { read the first token }
@@ -514,6 +513,7 @@ implementation
               akttokenpos:=oldtokenpos;
               akttokenpos:=oldtokenpos;
               block_type:=old_block_type;
               block_type:=old_block_type;
               current_scanner:=oldcurrent_scanner;
               current_scanner:=oldcurrent_scanner;
+              parser_current_file:=current_scanner.inputfile.name^;
               { restore cg }
               { restore cg }
               nextlabelnr:=oldnextlabelnr;
               nextlabelnr:=oldnextlabelnr;
               parse_only:=oldparse_only;
               parse_only:=oldparse_only;
@@ -556,7 +556,12 @@ implementation
               statement_level:=oldstatement_level;
               statement_level:=oldstatement_level;
               aktexceptblock:=0;
               aktexceptblock:=0;
               exceptblockcounter:=0;
               exceptblockcounter:=0;
+           end
+         else
+           begin
+              parser_current_file:='';
            end;
            end;
+
        { Shut down things when the last file is compiled }
        { Shut down things when the last file is compiled }
          if (compile_level=1) then
          if (compile_level=1) then
           begin
           begin
@@ -613,8 +618,6 @@ implementation
           end;
           end;
 
 
          dec(compile_level);
          dec(compile_level);
-         parser_current_file:=prev_name^;
-         stringdispose(prev_name);
          compiled_module:=old_compiled_module;
          compiled_module:=old_compiled_module;
 {$ifdef USEEXCEPT}
 {$ifdef USEEXCEPT}
          if longjump_used then
          if longjump_used then
@@ -625,7 +628,10 @@ implementation
 end.
 end.
 {
 {
   $Log$
   $Log$
-  Revision 1.29  2002-04-20 21:32:24  carl
+  Revision 1.30  2002-04-21 18:57:23  peter
+    * fixed memleaks when file can't be opened
+
+  Revision 1.29  2002/04/20 21:32:24  carl
   + generic FPC_CHECKPOINTER
   + generic FPC_CHECKPOINTER
   + first parameter offset in stack now portable
   + first parameter offset in stack now portable
   * rename some constants
   * rename some constants

+ 6 - 1
compiler/pdecvar.pas

@@ -272,6 +272,7 @@ implementation
                             (target_info.target=target_i386_go32v2) then
                             (target_info.target=target_i386_go32v2) then
                           begin
                           begin
                             consume(token);
                             consume(token);
+                            pt.free;
                             pt:=expr;
                             pt:=expr;
                             if is_constintnode(pt) then
                             if is_constintnode(pt) then
                               begin
                               begin
@@ -290,6 +291,7 @@ implementation
                  end
                  end
                 else
                 else
                   Message(parser_e_absolute_only_to_var_or_const);
                   Message(parser_e_absolute_only_to_var_or_const);
+                pt.free;
                 symdone:=true;
                 symdone:=true;
               end;
               end;
              { Handling of Delphi typed const = initialized vars ! }
              { Handling of Delphi typed const = initialized vars ! }
@@ -575,7 +577,10 @@ implementation
 end.
 end.
 {
 {
   $Log$
   $Log$
-  Revision 1.22  2001-11-20 18:48:26  peter
+  Revision 1.23  2002-04-21 18:57:24  peter
+    * fixed memleaks when file can't be opened
+
+  Revision 1.22  2001/11/20 18:48:26  peter
     * fixed initialized variables
     * fixed initialized variables
 
 
   Revision 1.21  2001/10/23 21:49:42  peter
   Revision 1.21  2001/10/23 21:49:42  peter

+ 11 - 2
compiler/scanner.pas

@@ -113,6 +113,7 @@ interface
           procedure tempcloseinputfile;
           procedure tempcloseinputfile;
           procedure saveinputfile;
           procedure saveinputfile;
           procedure restoreinputfile;
           procedure restoreinputfile;
+          procedure firstfile;
           procedure nextfile;
           procedure nextfile;
           procedure addfile(hp:tinputfile);
           procedure addfile(hp:tinputfile);
           procedure reload;
           procedure reload;
@@ -913,9 +914,14 @@ implementation
         invalid:=false;
         invalid:=false;
         in_asm_string:=false;
         in_asm_string:=false;
         macros:=tdictionary.create;
         macros:=tdictionary.create;
+      end;
+
+
+    procedure tscannerfile.firstfile;
+      begin
       { load block }
       { load block }
         if not openinputfile then
         if not openinputfile then
-         Message1(scan_f_cannot_open_input,fn);
+          Message1(scan_f_cannot_open_input,inputfile.name^);
         reload;
         reload;
       { process first read char }
       { process first read char }
         case c of
         case c of
@@ -2758,7 +2764,10 @@ exit_label:
 end.
 end.
 {
 {
   $Log$
   $Log$
-  Revision 1.35  2002-04-21 15:22:26  carl
+  Revision 1.36  2002-04-21 18:57:23  peter
+    * fixed memleaks when file can't be opened
+
+  Revision 1.35  2002/04/21 15:22:26  carl
   * first check .inc file extension
   * first check .inc file extension
 
 
   Revision 1.34  2002/04/21 07:24:09  carl
   Revision 1.34  2002/04/21 07:24:09  carl