Pārlūkot izejas kodu

free final_asmnode if not used to avoid memory leak

git-svn-id: trunk@22423 -
pierre 13 gadi atpakaļ
vecāks
revīzija
4f810f0918
1 mainītis faili ar 10 papildinājumiem un 1 dzēšanām
  1. 10 1
      compiler/psub.pas

+ 10 - 1
compiler/psub.pas

@@ -50,6 +50,7 @@ interface
         stackcheck_asmnode,
         stackcheck_asmnode,
         init_asmnode,
         init_asmnode,
         final_asmnode : tasmnode;
         final_asmnode : tasmnode;
+        final_used : boolean;
         dfabuilder : TDFABuilder;
         dfabuilder : TDFABuilder;
         destructor  destroy;override;
         destructor  destroy;override;
         procedure printproc(pass:string);
         procedure printproc(pass:string);
@@ -647,6 +648,8 @@ implementation
        begin
        begin
          if assigned(code) then
          if assigned(code) then
            code.free;
            code.free;
+         if not final_used then
+           final_asmnode.free;
          inherited destroy;
          inherited destroy;
        end;
        end;
 
 
@@ -716,6 +719,7 @@ implementation
                       begin
                       begin
                         include(tocode.flags,nf_block_with_exit);
                         include(tocode.flags,nf_block_with_exit);
                         addstatement(newstatement,final_asmnode);
                         addstatement(newstatement,final_asmnode);
+                        final_used:=true;
                       end;
                       end;
 
 
                     { Self can be nil when fail is called }
                     { Self can be nil when fail is called }
@@ -806,6 +810,7 @@ implementation
         current_filepos:=exitpos;
         current_filepos:=exitpos;
         exitlabel_asmnode:=casmnode.create_get_position;
         exitlabel_asmnode:=casmnode.create_get_position;
         final_asmnode:=casmnode.create_get_position;
         final_asmnode:=casmnode.create_get_position;
+        final_used:=false;
         bodyexitcode:=generate_bodyexit_block;
         bodyexitcode:=generate_bodyexit_block;
 
 
         { Generate procedure by combining init+body+final,
         { Generate procedure by combining init+body+final,
@@ -833,6 +838,7 @@ implementation
             { Generate code that will be in the try...finally }
             { Generate code that will be in the try...finally }
             finalcode:=internalstatements(codestatement);
             finalcode:=internalstatements(codestatement);
             addstatement(codestatement,final_asmnode);
             addstatement(codestatement,final_asmnode);
+            final_used:=true;
 
 
             current_filepos:=entrypos;
             current_filepos:=entrypos;
             wrappedbody:=ctryfinallynode.create_implicit(
             wrappedbody:=ctryfinallynode.create_implicit(
@@ -861,7 +867,10 @@ implementation
             addstatement(newstatement,exitlabel_asmnode);
             addstatement(newstatement,exitlabel_asmnode);
             addstatement(newstatement,bodyexitcode);
             addstatement(newstatement,bodyexitcode);
             if not is_constructor then
             if not is_constructor then
-              addstatement(newstatement,final_asmnode);
+              begin
+                addstatement(newstatement,final_asmnode);
+                final_used:=true;
+              end;
           end;
           end;
         do_firstpass(newblock);
         do_firstpass(newblock);
         code:=newblock;
         code:=newblock;