Folks,
I've just started to use and appreciate FPC & Lazarus and have found a small bug in TBinaryObjectReader.
The bug can be reproduced by creating a TReader with::
TReader.Create(nil,BUFF_SIZE); { <- It is 'legal' to create a Tfiler assigned to a 'nil' stream
but maybe a bit stupid )
try
///... more code
finally
TReader.Free; // <- This line will cause an access violation
end;
The code crashes because the internal TBinaryObjectReader attempts to access the stream in its destrucrtor without first testing if it is assigned. The following adjustment prevents the GPF ::
destructor TBinaryObjectReader.Destroy;
begin
If Assigned(FStream) then //<--- **test added here**
{ Seek back the amount of bytes that we didn't process until now: }
FStream.Seek(Integer(FBufPos) - Integer(FBufEnd), soFromCurrent);
if Assigned(FBuffer) then
FreeMem(FBuffer, FBufSize);
inherited Destroy;
end;
what are your thoughts?
R.E.S.P.E.C.T (jus like Franklin))
Si Mozzer