blob: 1d9b9835051643b54b251e6e8bfa837ebd052283 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
|
{ %OPT=-gh }
{$mode objfpc}{$h+}
{ Test that exception in object constructor does not cause memory leak }
uses sysutils;
type
pobj=^obj;
obj=object
constructor init;
destructor done; virtual;
end;
pobjnodestructor=^objnodestructor;
objnodestructor=object
constructor init;
end;
constructor obj.init;
begin
Abort;
end;
destructor obj.done;
begin
end;
constructor objnodestructor.init;
begin
Abort;
end;
var
ps: obj;
ps2: objnodestructor;
p: pobj;
p2: pobjnodestructor;
begin
HaltOnNotReleased:=true;
{ Test 1: object with destructor, dynamically allocated. Must free memory. }
try
new(p,init);
except
on EAbort do
else Halt(1);
end;
{ Test 2: object with destructor, statically allocated. Must not try to free memory. }
try
ps.init;
except
on EAbort do
else Halt(2);
end;
{ Test 3: object without destructor, dynamically allocated. }
try
new(p2,init);
except
on EAbort do
else Halt(3);
end;
{ Test 4: object without desturtor, statically allocated. }
try
ps2.init;
except
on EAbort do
else Halt(4);
end;
end.
|