In the following method, FreeMem(), throws an EAccessViolation. What are the possible reasons?
procedure TCustomDataset.FreeRecordBuffer(var Buffer: PChar);
begin
FreeMem(Buffer);
end;
EDIT: As far as I understand TDataset Buffers are only allocated in:
function TCustomDataset.AllocRecordBuffer: PChar;
begin
Result := AllocMem(GetBufferSize);
end;
and only freed in FreeRecordBuffer()
Now I've checked and in my case 2 buffers are allocated, the first one gets freed without a hitch, but the second causes FreeMem() to throw a EAccessViolation. I've also check(by writing down the pointer addresses) that both the address were given by AllocRecordBuffer() are passed to FreeRecordBuffer() and nothing else.
According to Delphi Basics FreeMem() should only throw an EInvalidPointer when the pointer is invalid.
EDIT: Found the problem, I overwrote memory.