Postgresql BlobRead Memory Leak

Forum related to version 6.5.1 (alpha) and 6.6.x (beta) of ZeosLib's DBOs

Moderators: gto, cipto_kh, EgonHugeist

Tom
Fresh Boarder
Fresh Boarder
Posts: 2
Joined: 04.08.2007, 10:14

Postgresql BlobRead Memory Leak

Postby Tom » 04.08.2007, 10:28

I use zeosdbo with Postgresql 7.3. and Delphi.

I use CreateBlobStream.
Memory Leak happend.

exp)

BlobStream := CreateBlobStream(TBlobField(Fields[1]), bmRead);
BlobStream.Free;

--------------

I found problem.
-- ZDbcPostgreSqlResultSet.pas

within:procedure TZPostgreSQLBlob.ReadBlob;

ReadStrem is not released.

725: SetStream(ReadStream);

I added this code.

if ReadStream <> Nil then
ReadStream.Free;
end;

User avatar
mdaems
Zeos Project Manager
Zeos Project Manager
Posts: 2766
Joined: 20.09.2005, 15:28
Location: Brussels, Belgium
Contact:

Postby mdaems » 05.08.2007, 23:51

Can you give a little more detail? Where exactly did you add the lines above. The function is short enough. Can you please copy/paste your version of the TZPostgreSQLBlob.ReadBlob function?

Mark

Tom
Fresh Boarder
Fresh Boarder
Posts: 2
Joined: 04.08.2007, 10:14

Postby Tom » 07.08.2007, 15:46

Sorry.

TZPostgreSQLBlob.ReadBlob is

Code: Select all

procedure TZPostgreSQLBlob.ReadBlob;
var
  BlobHandle: Integer;
  Buffer: array[0..1024] of Char;
  ReadNum: Integer;
  ReadStream: TMemoryStream;
begin
  if not Updated and (FBlobOid > 0) then
  begin
    BlobHandle := FPlainDriver.OpenLargeObject(FHandle, FBlobOid, INV_READ);
    CheckPostgreSQLError(nil, FPlainDriver, FHandle, lcOther, 'Read Large Object',nil);
    if BlobHandle >= 0 then
    begin
      ReadStream := TMemoryStream.Create;
      repeat
        ReadNum := FPlainDriver.ReadLargeObject(FHandle, BlobHandle,
          Buffer, 1024);
        if ReadNum > 0 then
        begin
          ReadStream.SetSize(ReadStream.Size + ReadNum);
          ReadStream.Write(Buffer, ReadNum);
        end;
      until ReadNum < 1024;
      FPlainDriver.CloseLargeObject(FHandle, BlobHandle);
      ReadStream.Position := 0;
    end else
      ReadStream := nil;
    SetStream(ReadStream);

    if ReadStream <> Nil then
        ReadStream.Free;

  end;
end;



ReadStream was Created, But is not Free.

Will I be wrong?

User avatar
cipto_kh
Senior Boarder
Senior Boarder
Posts: 83
Joined: 28.09.2005, 11:22
Location: Indonesia
Contact:

Postby cipto_kh » 08.08.2007, 10:30

if ReadStream <> Nil then
ReadStream.Free;

I think it should be:
if ReadStream <> Nil then
FreeAndNil(ReadStream);

Becasue the Free mothod didn't nil the instance.

User avatar
mdaems
Zeos Project Manager
Zeos Project Manager
Posts: 2766
Joined: 20.09.2005, 15:28
Location: Brussels, Belgium
Contact:

Postby mdaems » 26.11.2009, 22:17

Hi,

Thanks for reporting again, in the bug tracker this time.

I did apply the patch now. (in the easy version as you wrote it above, not an exact copy from the bug tracker)

Cipto, FreeAndNil is not necessary as the variable is only local and destroyed a few lines later at the end of the procedure.

Mark
Image


Return to “6.5.1 (alpha) - 6.6.x (beta)”

Who is online

Users browsing this forum: No registered users and 1 guest