Browse Source

* fixed memory leaks in case a TP-style object inherits from another object
type that contains managed types, but this child doesn't contain any
managed type itself (since r16632, the parent should be considered as a
field of the child in terms of needing initialization/finalization)

git-svn-id: trunk@22461 -

Jonas Maebe 13 years ago
parent
commit
e3b97d99c6
3 changed files with 60 additions and 1 deletions
  1. 1 0
      .gitattributes
  2. 4 1
      compiler/symdef.pas
  3. 55 0
      tests/test/tobject9.pp

+ 1 - 0
.gitattributes

@@ -11052,6 +11052,7 @@ tests/test/tobject5.pp svneol=native#text/pascal
 tests/test/tobject6.pp svneol=native#text/plain
 tests/test/tobject6.pp svneol=native#text/plain
 tests/test/tobject7.pp svneol=native#text/plain
 tests/test/tobject7.pp svneol=native#text/plain
 tests/test/tobject8.pp svneol=native#text/plain
 tests/test/tobject8.pp svneol=native#text/plain
+tests/test/tobject9.pp svneol=native#text/plain
 tests/test/toperator1.pp svneol=native#text/plain
 tests/test/toperator1.pp svneol=native#text/plain
 tests/test/toperator10.pp svneol=native#text/pascal
 tests/test/toperator10.pp svneol=native#text/pascal
 tests/test/toperator11.pp svneol=native#text/pascal
 tests/test/toperator11.pp svneol=native#text/pascal

+ 4 - 1
compiler/symdef.pas

@@ -5927,7 +5927,10 @@ implementation
             odt_interfacecorba:
             odt_interfacecorba:
               needs_inittable:=is_related(interface_iunknown);
               needs_inittable:=is_related(interface_iunknown);
             odt_object:
             odt_object:
-              needs_inittable:=tObjectSymtable(symtable).needs_init_final;
+              needs_inittable:=
+                tObjectSymtable(symtable).needs_init_final or
+                (assigned(childof) and
+                 childof.needs_inittable);
             odt_cppclass,
             odt_cppclass,
             odt_objcclass,
             odt_objcclass,
             odt_objcprotocol,
             odt_objcprotocol,

+ 55 - 0
tests/test/tobject9.pp

@@ -0,0 +1,55 @@
+{ %OPT=-gh }
+// Validate that objects with parent are finalized when statically allocated
+type
+  pobj = ^tobj;
+  tobj = object
+  public
+    foo: ansistring;
+    constructor init(const s: ansistring);
+    destructor done;
+  end;
+
+  pobj1 = ^tobj1;
+  tobj1 = object(tobj)
+    constructor init;
+    destructor done;
+  end;
+
+constructor tobj.init(const s: ansistring);
+begin
+  foo:=s;
+end;
+
+destructor tobj.done;
+begin
+end;
+
+constructor tobj1.init;
+var
+  s: ansistring;
+begin
+  s:='abc';
+  uniquestring(s);
+  inherited init(s);
+end;
+
+destructor tobj1.done;
+begin
+  inherited done;
+end;
+
+var
+  obj: tobj1;
+  
+procedure local;
+var
+  instance: tobj1;
+begin
+  instance.init;
+end;
+
+begin
+  HaltOnNotReleased:=true;
+  local;
+  obj.init;
+end.