Interfaces in records are not initialized properly
Original Reporter info from Mantis: sysrpl
-
Reporter name: Anthony Walter
Original Reporter info from Mantis: sysrpl
- Reporter name: Anthony Walter
Description:
If you have a record with an interface in a private section, it sometimes will not be properly initialized. Records of this type which are returned from functions or are local variables sometimes will reference a garbage interface pointer. Attempts to set the value of the interface can cause a segment fault as the compiler generates code to release a interface referencing garbage.
I marked the issue as major since I thought this kind of issue (managed types slipping through initialization) should never happen.
Steps to reproduce:
type
IVector = interface
end;
TVectorObject = class(TInterfaceObject, IVector) end;
TVector = record
private
FVector: IVector;
end;
function Test1: TVector;
begin
// may error randomly because Result.FVector already references garbage
Result.FVector := TVectorObject.Create;
end;
function Test2;
var
V: TVector;
begin
// may error randomly because V.FVector already references garbage
V.FVector := nil;
end;
Additional information:
Managed types in any complex type (classes, records, arrays) should be initialized and finalized automatically. It would seem that defining a record with a private field of interface type is not initialized correctly. I would guess that the finalization might also not be work as expected.
Mantis conversion info:
- Mantis ID: 24449
- OS: Ubuntu 32 bit
- OS Build: 12.04
- Build: trunk
- Platform: Linux
- Version: 2.7.1