[fpc-devel] Memory leak @ tobjectdef.getcopy

Blaise at blaise.ru Blaise at blaise.ru
Sun Dec 1 18:08:49 CET 2019


On 01.12.2019 19:15, Blaise at blaise.ru wrote:
> With the following two exceptions, there are no other assigned(vmtentries) checks before dereferencing.

And one assertion @ TVMTBuilder.generate_vmt :
> 	if assigned(_class.childof) then
> 	  begin
> 		if not assigned(_class.childof.vmtentries) then
> 		  internalerror(200810281);
> 		_class.copyvmtentries(_class.childof);
> 	  end;

Patch is amended.
(Originally, that was a part of another changeset, but I reckon it makes more sense here.)

-- 
βþ
-------------- next part --------------
# HG changeset patch
# User Blaise.ru
# Date 1575215603 -10800
#      01.12.2019 18:53:23 +0300
# Node ID 932f6f48e6c6a5726ff45882e9e64db773a9b979
# Parent  2ae482b988eb0d4f0eac5ce091b2c134d5998fd3
! memory leak @ tobjectdef.getcopy
= tobjectdef.vmtentries is never nil; no point in checking

diff -r 2ae482b988eb -r 932f6f48e6c6 ncgvmt.pas
--- a/ncgvmt.pas	01.12.2019 12:23:49 +0300
+++ b/ncgvmt.pas	01.12.2019 18:53:23 +0300
@@ -966,8 +966,6 @@
          hs : string;
 {$endif vtentry}
       begin
-        if not assigned(_class.VMTEntries) then
-          exit;
         for i:=0 to _class.VMTEntries.Count-1 do
          begin
            vmtentry:=pvmtentry(_class.vmtentries[i]);
diff -r 2ae482b988eb -r 932f6f48e6c6 nobj.pas
--- a/nobj.pas	01.12.2019 12:23:49 +0300
+++ b/nobj.pas	01.12.2019 18:53:23 +0300
@@ -910,11 +910,7 @@
 
         { inherit (copy) VMT from parent object }
         if assigned(_class.childof) then
-          begin
-            if not assigned(_class.childof.vmtentries) then
-              internalerror(200810281);
-            _class.copyvmtentries(_class.childof);
-          end;
+          _class.copyvmtentries(_class.childof);
 
         { process all procdefs, we must process the defs to
           keep the same order as that is written in the source
diff -r 2ae482b988eb -r 932f6f48e6c6 symdef.pas
--- a/symdef.pas	01.12.2019 12:23:49 +0300
+++ b/symdef.pas	01.12.2019 18:53:23 +0300
@@ -7287,7 +7287,7 @@
          if assigned(vmtentries) then
            begin
              resetvmtentries;
-             vmtentries.free;
+             vmtentries.Destroy;
              vmtentries:=nil;
            end;
          if assigned(vmcallstaticinfo) then
@@ -7330,11 +7330,7 @@
             for i:=0 to ImplementedInterfaces.count-1 do
               tobjectdef(result).ImplementedInterfaces.Add(TImplementedInterface(ImplementedInterfaces[i]).Getcopy);
           end;
-        if assigned(vmtentries) then
-          begin
-            tobjectdef(result).vmtentries:=TFPList.Create;
-            tobjectdef(result).copyvmtentries(self);
-          end;
+        tobjectdef(result).copyvmtentries(self);
       end;
 
 


More information about the fpc-devel mailing list