mirror of
https://gitlab.com/freepascal.org/fpc/source.git
synced 2025-10-22 11:01:43 +02:00
* always initialize/finalize global refcounted variables in units, also
when they are not used in the unit where they are defined (since they may be used elsewhere, discovered while analyzing mantis #13345) git-svn-id: trunk@12954 -
This commit is contained in:
parent
647fe5f237
commit
5cf4ab7642
2
.gitattributes
vendored
2
.gitattributes
vendored
@ -8804,6 +8804,8 @@ tests/webtbs/tw13313.pp svneol=native#text/plain
|
||||
tests/webtbs/tw13313a.pp svneol=native#text/plain
|
||||
tests/webtbs/tw1333.pp svneol=native#text/plain
|
||||
tests/webtbs/tw13343.pp svneol=native#text/plain
|
||||
tests/webtbs/tw13345x.pp svneol=native#text/plain
|
||||
tests/webtbs/tw13345y.pp svneol=native#text/plain
|
||||
tests/webtbs/tw1348.pp svneol=native#text/plain
|
||||
tests/webtbs/tw1351.pp svneol=native#text/plain
|
||||
tests/webtbs/tw1364.pp svneol=native#text/plain
|
||||
|
@ -1076,7 +1076,13 @@ implementation
|
||||
hp : tnode;
|
||||
begin
|
||||
if (tsym(p).typ in [staticvarsym,localvarsym]) and
|
||||
((tabstractvarsym(p).refs>0) or
|
||||
{ local (procedure or unit) variables only need initialization if
|
||||
they are used }
|
||||
((tabstractvarsym(p).refs>0) or
|
||||
{ global (unit) variables always need initialization, since
|
||||
they may also be used in another unit
|
||||
}
|
||||
(tabstractvarsym(p).owner.symtabletype=globalsymtable) or
|
||||
{ managed return symbols must be inited }
|
||||
((tsym(p).typ=localvarsym) and (vo_is_funcret in tlocalvarsym(p).varoptions))
|
||||
) and
|
||||
@ -1135,7 +1141,14 @@ implementation
|
||||
case tsym(p).typ of
|
||||
staticvarsym :
|
||||
begin
|
||||
if (tstaticvarsym(p).refs>0) and
|
||||
{ local (procedure or unit) variables only need finalization
|
||||
if they are used
|
||||
}
|
||||
if ((tstaticvarsym(p).refs>0) or
|
||||
{ global (unit) variables always need finalization, since
|
||||
they may also be used in another unit
|
||||
}
|
||||
(tstaticvarsym(p).owner.symtabletype=globalsymtable)) and
|
||||
(tstaticvarsym(p).varspez<>vs_const) and
|
||||
not(vo_is_funcret in tstaticvarsym(p).varoptions) and
|
||||
not(vo_is_external in tstaticvarsym(p).varoptions) and
|
||||
|
17
tests/webtbs/tw13345x.pp
Normal file
17
tests/webtbs/tw13345x.pp
Normal file
@ -0,0 +1,17 @@
|
||||
{ %opt=-gh }
|
||||
{ %recompile }
|
||||
|
||||
{$mode delphi}
|
||||
|
||||
uses
|
||||
tw13345y;
|
||||
|
||||
type
|
||||
tc = class(tinterfacedobject,ta)
|
||||
end;
|
||||
|
||||
begin
|
||||
HaltOnNotReleased:=true;
|
||||
{ should be automatically freed by the finalization code of tw13345y }
|
||||
c:=tc.create;
|
||||
end.
|
16
tests/webtbs/tw13345y.pp
Normal file
16
tests/webtbs/tw13345y.pp
Normal file
@ -0,0 +1,16 @@
|
||||
unit tw13345y;
|
||||
|
||||
{$mode delphi}
|
||||
|
||||
interface
|
||||
|
||||
type
|
||||
ta = interface
|
||||
end;
|
||||
|
||||
var
|
||||
c: ta;
|
||||
|
||||
implementation
|
||||
|
||||
end.
|
Loading…
Reference in New Issue
Block a user