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 is not initialized. If you attempt to return or manipulate a local variable of a record of this type you will get errors occasionally as the interface will attempt to release a garbage pointer.
Steps to reproduce:
type
IVector = interface
end;
TVector = record
private
FVector: IVector;
end;
function GetVector: TVector;
begin
// will error randomly because Result.FVector already has garbage in it
Result.FVector := TVectorObject.Create;
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 also guess that the finalization might not work as expected also.
Mantis conversion info:
- Mantis ID: 24447
- OS: Ubuntu 32 bit
- OS Build: 12.04
- Build: 2.7.1 trunk
- Platform: Linux