فهرست منبع

* fixed some memory leaks

peter 24 سال پیش
والد
کامیت
6eb671f761
6فایلهای تغییر یافته به همراه64 افزوده شده و 68 حذف شده
  1. 8 2
      compiler/cclasses.pas
  2. 9 31
      compiler/fmodule.pas
  3. 24 19
      compiler/ogcoff.pas
  4. 13 9
      compiler/pmodules.pas
  5. 5 3
      compiler/scandir.inc
  6. 5 4
      compiler/symtable.pas

+ 8 - 2
compiler/cclasses.pas

@@ -672,7 +672,10 @@ end;
          exit;
         p:=find(s);
         if assigned(p) then
-         inherited Remove(p);
+         begin
+           inherited Remove(p);
+           p.Free;
+         end;
       end;
 
 
@@ -1634,7 +1637,10 @@ end;
 end.
 {
   $Log$
-  Revision 1.4  2001-03-05 21:40:01  peter
+  Revision 1.5  2001-03-13 18:45:06  peter
+    * fixed some memory leaks
+
+  Revision 1.4  2001/03/05 21:40:01  peter
     * fixed tdynamicarray.readstream
 
   Revision 1.3  2000/12/29 21:57:27  peter

+ 9 - 31
compiler/fmodule.pas

@@ -304,8 +304,8 @@ uses
         found:=false;
         data:=stringdup(s);
       end;
-      
-      
+
+
     destructor tExternalsItem.Destroy;
       begin
         stringdispose(data);
@@ -699,37 +699,18 @@ uses
         e : extstr;
       begin
         FSplit(s,p,n,e);
-      { Programs have the name program to don't conflict with dup id's }
+        { Programs have the name 'Program' to don't conflict with dup id's }
         if _is_unit then
-         begin
-{$ifdef UNITALIASES}
-           modulename:=stringdup(GetUnitAlias(Upper(n)));
-           realmodulename:=stringdup(GetUnitAlias(n));
-{$else}
-           modulename:=stringdup(Upper(n));
-           realmodulename:=stringdup(n);
-{$endif}
-         end
+         inherited create(n)
         else
-         begin
-           modulename:=stringdup('PROGRAM');
-           realmodulename:=stringdup('Program');
-         end;
+         inherited create('Program');
         mainsource:=stringdup(s);
-        ppufilename:=nil;
-        objfilename:=nil;
-        asmfilename:=nil;
-        staticlibfilename:=nil;
-        sharedlibfilename:=nil;
-        exefilename:=nil;
         { Dos has the famous 8.3 limit :( }
 {$ifdef SHORTASMPREFIX}
         asmprefix:=stringdup(FixFileName('as'));
 {$else}
         asmprefix:=stringdup(FixFileName(n));
 {$endif}
-        outputpath:=nil;
-        path:=nil;
         setfilename(p+n,true);
         localunitsearchpath:=TSearchPathList.Create;
         localobjectsearchpath:=TSearchPathList.Create;
@@ -737,7 +718,6 @@ uses
         locallibrarysearchpath:=TSearchPathList.Create;
         used_units:=TLinkedList.Create;
         dependent_units:=TLinkedList.Create;
-        sourcefiles:=TInputFileManager.Create;
         resourcefiles:=TStringList.Create;
         linkunitofiles:=TLinkContainer.Create;
         linkunitstaticlibs:=TLinkContainer.Create;
@@ -756,8 +736,6 @@ uses
         interface_crc:=0;
         do_reload:=false;
         unitcount:=1;
-        inc(global_unit_count);
-        unit_index:=global_unit_count;
         do_assemble:=false;
         do_compile:=false;
         sources_avail:=true;
@@ -811,9 +789,6 @@ uses
         externals:=nil;
         if assigned(scanner) then
           pscannerfile(scanner)^.invalid:=true;
-        if assigned(sourcefiles) then
-         sourcefiles.Free;
-        sourcefiles:=nil;
         used_units.free;
         dependent_units.free;
         resourcefiles.Free;
@@ -906,7 +881,10 @@ uses
 end.
 {
   $Log$
-  Revision 1.8  2001-03-06 18:28:02  peter
+  Revision 1.9  2001-03-13 18:45:06  peter
+    * fixed some memory leaks
+
+  Revision 1.8  2001/03/06 18:28:02  peter
     * patch from Pavel with a new and much faster DLL Scanner for
       automatic importing so $linklib works for DLLs. Thanks Pavel!
 

+ 24 - 19
compiler/ogcoff.pas

@@ -51,6 +51,8 @@ interface
 
        tcoffdata = class(tobjectdata)
        private
+         Fstrs,
+         Fsyms  : Tdynamicarray;
          win32   : boolean;
          procedure reset;
        public
@@ -63,8 +65,6 @@ interface
          procedure writesymbol(p:pasmsymbol);override;
          procedure writestabs(section:tsection;offset:longint;p:pchar;nidx,nother,line:longint;reloc:boolean);override;
          procedure writesymstabs(section:tsection;offset:longint;p:pchar;ps:pasmsymbol;nidx,nother,line:longint;reloc:boolean);override;
-         strs,
-         syms  : Tdynamicarray;
        end;
 
        tcoffobjectoutput = class(tobjectoutput)
@@ -211,6 +211,8 @@ implementation
 
     destructor tcoffdata.destroy;
       begin
+        FSyms.Free;
+        FStrs.Free;
         inherited destroy;
       end;
 
@@ -219,8 +221,8 @@ implementation
       var
         s : string;
       begin
-        Syms:=TDynamicArray.Create(symbolresize);
-        Strs:=TDynamicArray.Create(strsresize);
+        FSyms:=TDynamicArray.Create(symbolresize);
+        FStrs:=TDynamicArray.Create(strsresize);
         { we need at least the following 3 sections }
         createsection(sec_code);
         createsection(sec_data);
@@ -320,9 +322,9 @@ implementation
            s:=p^.name;
            if length(s)>8 then
             begin
-              sym.nameidx:=Strs.size+4;
-              Strs.writestr(s);
-              Strs.writestr(#0);
+              sym.nameidx:=FStrs.size+4;
+              FStrs.writestr(s);
+              FStrs.writestr(#0);
             end
            else
             begin
@@ -330,9 +332,9 @@ implementation
               sym.namestr:=s;
             end;
            { update the asmsymbol index }
-           p^.idx:=Syms.size div sizeof(TOutputSymbol);
+           p^.idx:=FSyms.size div sizeof(TOutputSymbol);
            { write the symbol }
-           Syms.write(sym,sizeof(toutputsymbol));
+           FSyms.write(sym,sizeof(toutputsymbol));
          end
         else
          begin
@@ -653,10 +655,10 @@ implementation
                FWriter.write(secrec,sizeof(secrec));
              end;
            { The real symbols }
-           Syms.seek(0);
-           for i:=1 to Syms.size div sizeof(TOutputSymbol) do
+           FSyms.seek(0);
+           for i:=1 to FSyms.size div sizeof(TOutputSymbol) do
             begin
-              Syms.read(sym,sizeof(TOutputSymbol));
+              FSyms.read(sym,sizeof(TOutputSymbol));
               if sym.bind=AB_LOCAL then
                 globalval:=3
               else
@@ -739,7 +741,7 @@ implementation
            header.mach:=$14c;
            header.nsects:=nsects;
            header.sympos:=sympos;
-           header.syms:=(Syms.size div sizeof(TOutputSymbol))+initsym;
+           header.syms:=(FSyms.size div sizeof(TOutputSymbol))+initsym;
            if gotreloc then
             header.flag:=$104
            else
@@ -789,9 +791,9 @@ implementation
          { Symbols }
            write_symbols;
          { Strings }
-           i:=Strs.size+4;
+           i:=FStrs.size+4;
            FWriter.write(i,4);
-           hp:=Strs.firstblock;
+           hp:=FStrs.firstblock;
            while assigned(hp) do
             begin
               FWriter.write(hp^.data,hp^.used);
@@ -908,8 +910,8 @@ implementation
                end
               else
                begin
-                 Strs.Seek(sym.strpos-4);
-                 Strs.Read(strname[1],255);
+                 FStrs.Seek(sym.strpos-4);
+                 FStrs.Read(strname[1],255);
                  strname[255]:=#0;
                end;
               strname[0]:=chr(strlen(@strname[1]));
@@ -1064,7 +1066,7 @@ implementation
               Comment(V_Error,'Error reading coff file');
               exit;
             end;
-           if not Reader.ReadArray(Strs,Strsize-4) then
+           if not Reader.ReadArray(FStrs,Strsize-4) then
             begin
               Comment(V_Error,'Error reading coff file');
               exit;
@@ -1099,7 +1101,10 @@ implementation
 end.
 {
   $Log$
-  Revision 1.9  2001-03-05 21:40:38  peter
+  Revision 1.10  2001-03-13 18:45:07  peter
+    * fixed some memory leaks
+
+  Revision 1.9  2001/03/05 21:40:38  peter
     * more things for tcoffobjectinput
 
   Revision 1.8  2000/12/25 00:07:26  peter

+ 13 - 9
compiler/pmodules.pas

@@ -56,7 +56,7 @@ implementation
        cgai386,
   {$ifndef NOTARGETWIN32}
        t_win32,
-  {$endif}     
+  {$endif}
 {$endif i386}
 {$endif newcg}
        link,assemble,import,export,gendef,ppu,comprsrc,
@@ -81,11 +81,11 @@ implementation
   {$ifndef NOTARGETWIN32}
              target_i386_win32 :
                DLLScanner:=tDLLscannerWin32.create;
-  {$endif}               
+  {$endif}
 {$endif}
              else
-               internalerror(769795413);  
-           end;              
+               internalerror(769795413);
+           end;
            { Walk all shared libs }
            While not current_module.linkOtherSharedLibs.Empty do
             begin
@@ -103,7 +103,7 @@ implementation
               importlib.generatelib;
             end;
          end;
-          
+
         { create the .s file and assemble it }
         GenerateAsm(false);
 
@@ -1497,6 +1497,10 @@ implementation
          current_module.localsymtable:=st;
          refsymtable:=st;
 
+         { a unit compiled at command line must be inside the loaded_unit list }
+         if (compile_level=1) then
+           loaded_units.insert(current_module);
+
          { load standard units (system,objpas,profile unit) }
          loaddefaultunits;
 
@@ -1507,9 +1511,6 @@ implementation
          if token=_USES then
            loadunits;
 
-         { necessary for browser }
-         loaded_units.insert(current_module);
-
 {$ifndef DONOTCHAINOPERATORS}
          pstoredsymtable(symtablestack)^.chainoperators;
 {$endif DONOTCHAINOPERATORS}
@@ -1662,7 +1663,10 @@ implementation
 end.
 {
   $Log$
-  Revision 1.24  2001-03-06 18:28:02  peter
+  Revision 1.25  2001-03-13 18:45:07  peter
+    * fixed some memory leaks
+
+  Revision 1.24  2001/03/06 18:28:02  peter
     * patch from Pavel with a new and much faster DLL Scanner for
       automatic importing so $linklib works for DLLs. Thanks Pavel!
 

+ 5 - 3
compiler/scandir.inc

@@ -701,6 +701,7 @@ const
          { load new file }
            hp:=do_openinputfile(foundfile);
            current_scanner^.addfile(hp);
+           current_module.sourcefiles.register_file(hp);
            if not current_scanner^.openinputfile then
             Message1(scan_f_cannot_open_includefile,hs);
            Message1(scan_t_start_include_file,current_scanner^.inputfile.path^+current_scanner^.inputfile.name^);
@@ -711,8 +712,6 @@ const
             #10,
             #13 : current_scanner^.linebreak;
            end;
-         { register for refs }
-           current_module.sourcefiles.register_file(hp);
          end;
       end;
 
@@ -1395,7 +1394,10 @@ const
 
 {
   $Log$
-  Revision 1.18  2001-02-20 21:41:18  peter
+  Revision 1.19  2001-03-13 18:45:07  peter
+    * fixed some memory leaks
+
+  Revision 1.18  2001/02/20 21:41:18  peter
     * new fixfilename, findfile for unix. Look first for lowercase, then
       NormalCase and last for UPPERCASE names.
 

+ 5 - 4
compiler/symtable.pas

@@ -1383,6 +1383,7 @@ implementation
            hcontainer.add(s,mask);
          end;
         current_ppu^.writeentry(id);
+        p.Free;
         p:=hcontainer;
       end;
 
@@ -2368,16 +2369,16 @@ implementation
         dispose(generrordef,done);
 {$ifdef UNITALIASES}
         dispose(unitaliases,done);
-{$endif}
-{$ifdef MEMDEBUG}
-       writeln('Manglednames: ',manglenamesize,' bytes');
 {$endif}
      end;
 
 end.
 {
   $Log$
-  Revision 1.27  2001-03-11 22:58:51  peter
+  Revision 1.28  2001-03-13 18:45:07  peter
+    * fixed some memory leaks
+
+  Revision 1.27  2001/03/11 22:58:51  peter
     * getsym redesign, removed the globals srsym,srsymtable
 
   Revision 1.26  2001/02/21 19:37:19  peter