Browse Source

* memory leaks for ansistring type casts fixed

florian 27 years ago
parent
commit
802fd8fb5c
3 changed files with 32 additions and 20 deletions
  1. 11 7
      compiler/cg386add.pas
  2. 5 2
      compiler/cg386cal.pas
  3. 16 11
      compiler/cg386cnv.pas

+ 11 - 7
compiler/cg386add.pas

@@ -1156,16 +1156,17 @@ implementation
 
 
                    if p^.treetype=muln then
                    if p^.treetype=muln then
                      begin
                      begin
-                        if cs_check_overflow in aktlocalswitches then
-                          push_int(1)
-                        else
-                          push_int(0);
                         release_qword_loc(p^.left^.location);
                         release_qword_loc(p^.left^.location);
                         release_qword_loc(p^.right^.location);
                         release_qword_loc(p^.right^.location);
                         p^.location.registerlow:=getexplicitregister32(R_EAX);
                         p^.location.registerlow:=getexplicitregister32(R_EAX);
                         p^.location.registerhigh:=getexplicitregister32(R_EDX);
                         p^.location.registerhigh:=getexplicitregister32(R_EDX);
-                        { ($80 shr byte(r) }
-                        pushusedregisters(pushedreg,$ff);
+                        pushusedregisters(pushedreg,$ff
+                          and not($80 shr byte(p^.location.registerlow))
+                          and not($80 shr byte(p^.location.registerhigh)));
+                        if cs_check_overflow in aktlocalswitches then
+                          push_int(1)
+                        else
+                          push_int(0);
                         emit_pushq_loc(p^.left^.location);
                         emit_pushq_loc(p^.left^.location);
                         emit_pushq_loc(p^.right^.location);
                         emit_pushq_loc(p^.right^.location);
                         if porddef(p^.resulttype)^.typ=u64bit then
                         if porddef(p^.resulttype)^.typ=u64bit then
@@ -1733,7 +1734,10 @@ implementation
 end.
 end.
 {
 {
   $Log$
   $Log$
-  Revision 1.36  1998-12-19 00:23:40  florian
+  Revision 1.37  1998-12-22 13:10:56  florian
+    * memory leaks for ansistring type casts fixed
+
+  Revision 1.36  1998/12/19 00:23:40  florian
     * ansistring memory leaks fixed
     * ansistring memory leaks fixed
 
 
   Revision 1.35  1998/12/11 23:36:06  florian
   Revision 1.35  1998/12/11 23:36:06  florian

+ 5 - 2
compiler/cg386cal.pas

@@ -1489,7 +1489,7 @@ implementation
                                       if not (cs_compilesystem in aktmoduleswitches) then
                                       if not (cs_compilesystem in aktmoduleswitches) then
                                       concat_external('FPC_WIDESTR_DECR_REF',EXT_NEAR);
                                       concat_external('FPC_WIDESTR_DECR_REF',EXT_NEAR);
                                    end;
                                    end;
-
+                                 ungetiftemp(hr);
                                  popusedregisters(pushedregs);
                                  popusedregisters(pushedregs);
                               end
                               end
                             else
                             else
@@ -1665,7 +1665,10 @@ implementation
 end.
 end.
 {
 {
   $Log$
   $Log$
-  Revision 1.54  1998-12-19 00:23:41  florian
+  Revision 1.55  1998-12-22 13:10:58  florian
+    * memory leaks for ansistring type casts fixed
+
+  Revision 1.54  1998/12/19 00:23:41  florian
     * ansistring memory leaks fixed
     * ansistring memory leaks fixed
 
 
   Revision 1.53  1998/12/11 00:02:47  peter
   Revision 1.53  1998/12/11 00:02:47  peter

+ 16 - 11
compiler/cg386cnv.pas

@@ -477,7 +477,6 @@ implementation
 
 
     var
     var
        ltemptoremove : plinkedlist;
        ltemptoremove : plinkedlist;
-       destroys : boolean;
 
 
     procedure second_string_to_string(pto,pfrom : ptree;convtyp : tconverttype);
     procedure second_string_to_string(pto,pfrom : ptree;convtyp : tconverttype);
 
 
@@ -509,8 +508,10 @@ implementation
                    begin
                    begin
                       gettempofsizereference(pto^.resulttype^.size,pto^.location.reference);
                       gettempofsizereference(pto^.resulttype^.size,pto^.location.reference);
                       loadansi2short(pfrom,pto);
                       loadansi2short(pfrom,pto);
+                      { this is done in secondtypeconv (FK)
                       removetemps(exprasmlist,temptoremove);
                       removetemps(exprasmlist,temptoremove);
                       destroys:=true;
                       destroys:=true;
+                      }
                    end;
                    end;
                  st_widestring:
                  st_widestring:
                    begin
                    begin
@@ -546,7 +547,7 @@ implementation
                       pto^.location.loc:=LOC_REFERENCE;
                       pto^.location.loc:=LOC_REFERENCE;
                       clear_reference(pto^.location.reference);
                       clear_reference(pto^.location.reference);
                       gettempofsizereference(pto^.resulttype^.size,pto^.location.reference);
                       gettempofsizereference(pto^.resulttype^.size,pto^.location.reference);
-                      temptoremove^.concat(new(ptemptodestroy,init(pto^.location.reference,pto^.resulttype)));
+                      ltemptoremove^.concat(new(ptemptodestroy,init(pto^.location.reference,pto^.resulttype)));
                       exprasmlist^.concat(new(pai386,op_const_ref(A_MOV,S_L,0,newreference(pto^.location.reference))));
                       exprasmlist^.concat(new(pai386,op_const_ref(A_MOV,S_L,0,newreference(pto^.location.reference))));
                       pushusedregisters(pushed,$ff);
                       pushusedregisters(pushed,$ff);
                       emit_push_lea_loc(pfrom^.location);
                       emit_push_lea_loc(pfrom^.location);
@@ -746,7 +747,7 @@ implementation
            st_ansistring :
            st_ansistring :
              begin
              begin
                gettempofsizereference(4,pto^.location.reference);
                gettempofsizereference(4,pto^.location.reference);
-               temptoremove^.concat(new(ptemptodestroy,init(pto^.location.reference,pto^.resulttype)));
+               ltemptoremove^.concat(new(ptemptodestroy,init(pto^.location.reference,pto^.resulttype)));
                exprasmlist^.concat(new(pai386,op_const_ref(A_MOV,S_L,0,newreference(pto^.location.reference))));
                exprasmlist^.concat(new(pai386,op_const_ref(A_MOV,S_L,0,newreference(pto^.location.reference))));
                pushusedregisters(pushed,$ff);
                pushusedregisters(pushed,$ff);
                emit_pushw_loc(pfrom^.location);
                emit_pushw_loc(pfrom^.location);
@@ -1235,6 +1236,8 @@ implementation
              begin
              begin
                 stringdispose(pto^.location.reference.symbol);
                 stringdispose(pto^.location.reference.symbol);
                 gettempofsizereference(pto^.resulttype^.size,pto^.location.reference);
                 gettempofsizereference(pto^.resulttype^.size,pto^.location.reference);
+                ltemptoremove^.concat(new(ptemptodestroy,init(pto^.location.reference,pto^.resulttype)));
+                exprasmlist^.concat(new(pai386,op_const_ref(A_MOV,S_L,0,newreference(pto^.location.reference))));
                 case pfrom^.location.loc of
                 case pfrom^.location.loc of
                    LOC_REGISTER,LOC_CREGISTER:
                    LOC_REGISTER,LOC_CREGISTER:
                      begin
                      begin
@@ -1336,10 +1339,12 @@ implementation
 
 
       begin
       begin
          { the ansi string disposing is a little bit hairy: }
          { the ansi string disposing is a little bit hairy: }
-         destroys:=false;
          oldrl:=temptoremove;
          oldrl:=temptoremove;
          temptoremove:=new(plinkedlist,init);
          temptoremove:=new(plinkedlist,init);
 
 
+         { the helper routines need access to the release list }
+         ltemptoremove:=oldrl;
+
          { this isn't good coding, I think tc_bool_2_int, shouldn't be }
          { this isn't good coding, I think tc_bool_2_int, shouldn't be }
          { type conversion (FK)                                        }
          { type conversion (FK)                                        }
 
 
@@ -1352,14 +1357,11 @@ implementation
               if codegenerror then
               if codegenerror then
                exit;
                exit;
            end;
            end;
-         { the helper routines need access to the release list }
-         ltemptoremove:=temptoremove;
-         {the second argument only is for maybe_range_checking !}
+         { the second argument only is for maybe_range_checking !}
          secondconvert[p^.convtyp](p,p^.left,p^.convtyp);
          secondconvert[p^.convtyp](p,p^.left,p^.convtyp);
 
 
-         { are the temp. ansistrings been destroyed ? }
-         if not destroys then
-           oldrl^.concatlist(temptoremove);
+         { clean up all temp. objects (ansi/widestrings) }
+         removetemps(exprasmlist,temptoremove);
          dispose(temptoremove,done);
          dispose(temptoremove,done);
          temptoremove:=oldrl;
          temptoremove:=oldrl;
       end;
       end;
@@ -1474,7 +1476,10 @@ implementation
 end.
 end.
 {
 {
   $Log$
   $Log$
-  Revision 1.42  1998-12-19 00:23:42  florian
+  Revision 1.43  1998-12-22 13:10:59  florian
+    * memory leaks for ansistring type casts fixed
+
+  Revision 1.42  1998/12/19 00:23:42  florian
     * ansistring memory leaks fixed
     * ansistring memory leaks fixed
 
 
   Revision 1.41  1998/11/30 19:48:54  peter
   Revision 1.41  1998/11/30 19:48:54  peter