Memory Leak - Zeoslib 6.6.0 - Beta, Delphi 6 and MySQL 4.1

In this forum all bug reports concerning the 6.x branch will be gahtered. You have the possibility to track the bug fix process.

Moderators: EgonHugeist, mdaems

Post Reply
jacques.bernardes
Fresh Boarder
Fresh Boarder
Posts: 10
Joined: 11.10.2006, 21:19

Memory Leak - Zeoslib 6.6.0 - Beta, Delphi 6 and MySQL 4.1

Post by jacques.bernardes »

The memory leak is stil present in the 6.6.x version, in both Delphi and Lazarus version.

Query.SQL.Clear;
Query.SQL.Add('SELECT user, password FROM mysql.users LIMIT 3;');
while 1=1 do begin
Query.Open;
Query.Close;
end;

This simple code is enougth to eat all avaliable memory on system after some time. In my opinion the problem is in metadata unit, when closing.

That's it


Jacques
jacques.bernardes
Fresh Boarder
Fresh Boarder
Posts: 10
Joined: 11.10.2006, 21:19

Post by jacques.bernardes »

Hi

I' m trying to find the memory leak using valgrind. With ZeosLib 6.6.0, Lazarus, the following code


program MemLeak;

{$MODE Delphi}

{$APPTYPE CONSOLE}

uses Sysutils, ZDataset, ZConnection;


var q : TZQuery;
c : TZconnection;
begin
c :=TZConnection.Create(nil);
q := TZQuery.Create(nil);
c.HostName := '127.0.0.1';
c.Database:='mysql';
c.User:='root';
c.Password:='';
c.Protocol:='mysql-4.1';
c.Connected:=True;
q.Connection:=c;
q.SQL.Clear;
q.SQL.Add('SELECT user, password, host FROM user LIMIT 1;');
q.Open;
while 1=1 do begin
q.Close;
q.Open;
writeln('Abri e fechei '+IntToStr(q.RecordCount));
end;
q.Close;
c.Connected:=False;
q.Free;
c.Free;
end.


gave me the following valgrind exit


jacques@drfcxl137b ~/Srf/Contabiliza $ valgrind --leak-check=full ./MemLeak
==23671== Memcheck, a memory error detector.
==23671== Copyright (C) 2002-2006, and GNU GPL'd, by Julian Seward et al.
==23671== Using LibVEX rev 1658, a library for dynamic binary translation.
==23671== Copyright (C) 2004-2006, and GNU GPL'd, by OpenWorks LLP.
==23671== Using valgrind-3.2.1, a dynamic binary instrumentation framework.
==23671== Copyright (C) 2000-2006, and GNU GPL'd, by Julian Seward et al.
==23671== For more details, rerun with: -v
==23671==
An unhandled exception occurred at $080FC47C :
\SQLException : Unsupported protocol: zsql-4.1
$080FC47C
$080DA794
$080DA246
$080B2232
$080736ED
$08072AC3
$08048C0A

==23671== Invalid free() / delete / delete[]
==23671== at 0x4020416: free (in /usr/lib/valgrind/x86-linux/vgpreload_memcheck.so)
==23671== by 0x416E743: __libc_freeres (in /lib/libc-2.4.so)
==23671== by 0x401C21A: _vgnU_freeres (in /usr/lib/valgrind/x86-linux/vgpreload_core.so)
==23671== by 0x41080B3: _Exit (in /lib/libc-2.4.so)
==23671== by 0x409686B: (below main) (in /lib/libc-2.4.so)
==23671== Address 0xFFFFFFFF is not stack'd, malloc'd or (recently) free'd
==23671==
==23671== ERROR SUMMARY: 1 errors from 1 contexts (suppressed: 21 from 1)
==23671== malloc/free: in use at exit: 286,730 bytes in 617 blocks.
==23671== malloc/free: 1,348 allocs, 732 frees, 575,480 bytes allocated.
==23671== For counts of detected errors, rerun with: -v
==23671== searching for pointers to 617 not-freed blocks.
==23671== checked 1,387,412 bytes.
==23671==
==23671==
==23671== 84 (36 direct, 48 indirect) bytes in 1 blocks are definitely lost in loss record 1 of 5
==23671== at 0x40209DA: malloc (in /usr/lib/valgrind/x86-linux/vgpreload_memcheck.so)
==23671== by 0x8060214: (within /home/jacques/Srf/Contabiliza/MemLeak)
==23671== by 0x8058C78: SYSTEM_GETMEM$POINTER$LONGINT (in /home/jacques/Srf/Contabiliza/MemLeak)
==23671== by 0x8052DF7: SYSTEM_TOBJECT_$__NEWINSTANCE$$TOBJECT (in /home/jacques/Srf/Contabiliza/MemLeak)
==23671== by 0x805391D: SYSTEM_TINTERFACEDOBJECT_$__NEWINSTANCE$$TOBJECT (in /home/jacques/Srf/Contabiliza/MemLeak)
==23671== by 0x80D743C: ZDBCDBLIB_TZDBLIBDRIVER_$__CREATE$$TZDBLIBDRIVER (ZDbcDbLib.pas:148)
==23671== by 0x80D9CEB: ZDBCDBLIB_init (ZDbcDbLib.pas:740)
==23671== by 0x8056E6C: fpc_initializeunits (in /home/jacques/Srf/Contabiliza/MemLeak)
==23671== by 0x8048AF3: main (MemLeak.lpr:12)
==23671==
==23671==
==23671== 96 bytes in 3 blocks are possibly lost in loss record 3 of 5
==23671== at 0x40209DA: malloc (in /usr/lib/valgrind/x86-linux/vgpreload_memcheck.so)
==23671== by 0x8060344: (within /home/jacques/Srf/Contabiliza/MemLeak)
==23671== by 0x805913C: SYSTEM_REALLOCMEM$POINTER$LONGINT$$POINTER (in /home/jacques/Srf/Contabiliza/MemLeak)
==23671== by 0x8085E6B: DB_TDATASET_$__CREATE$TCOMPONENT$$TDATASET (in /home/jacques/Srf/Contabiliza/MemLeak)
==23671== by 0x807B292: ZABSTRACTRODATASET_TZABSTRACTRODATASET_$__CREATE$TCOMPONENT$$TZABSTRACTRODATASET (ZAbstractRODataset.pas:477)
==23671== by 0x80830AE: ZABSTRACTDATASET_TZABSTRACTDATASET_$__CREATE$TCOMPONENT$$TZABSTRACTDATASET (ZAbstractDataset.pas:191)
==23671== by 0x8048B8A: main (MemLeak.lpr:14)
==23671==
==23671==
==23671== 160 bytes in 2 blocks are possibly lost in loss record 4 of 5
==23671== at 0x4020B0D: realloc (in /usr/lib/valgrind/x86-linux/vgpreload_memcheck.so)
==23671== by 0x8060363: (within /home/jacques/Srf/Contabiliza/MemLeak)
==23671== by 0x805913C: SYSTEM_REALLOCMEM$POINTER$LONGINT$$POINTER (in /home/jacques/Srf/Contabiliza/MemLeak)
==23671== by 0x80F3F74: ZCOLLECTIONS_TZCOLLECTION_$__SETCAPACITY$LONGINT (ZCollections.pas:297)
==23671== by 0x80F3EE8: ZCOLLECTIONS_TZCOLLECTION_$__GROW (ZCollections.pas:282)
==23671== by 0x80F4281: ZCOLLECTIONS_TZCOLLECTION_$__ADD$IUNKNOWN$$LONGINT (ZCollections.pas:355)
==23671== by 0x81BB50C: ZFUNCTIONS_TZDEFAULTFUNCTIONSLIST_$__CREATE$$TZDEFAULTFUNCTIONSLIST (ZFunctions.pas:444)
==23671== by 0x80C3132: ZEXPRESSION_TZEXPRESSION_$__CREATE$$TZEXPRESSION (ZExpression.pas:323)
==23671== by 0x807B391: ZABSTRACTRODATASET_TZABSTRACTRODATASET_$__CREATE$TCOMPONENT$$TZABSTRACTRODATASET (ZAbstractRODataset.pas:493)
==23671== by 0x80830AE: ZABSTRACTDATASET_TZABSTRACTDATASET_$__CREATE$TCOMPONENT$$TZABSTRACTDATASET (ZAbstractDataset.pas:191)
==23671== by 0x8048B8A: main (MemLeak.lpr:14)
==23671==
==23671==
==23671== 286,390 bytes in 609 blocks are possibly lost in loss record 5 of 5
==23671== at 0x40209DA: malloc (in /usr/lib/valgrind/x86-linux/vgpreload_memcheck.so)
==23671== by 0x8060214: (within /home/jacques/Srf/Contabiliza/MemLeak)
==23671== by 0x8058C78: SYSTEM_GETMEM$POINTER$LONGINT (in /home/jacques/Srf/Contabiliza/MemLeak)
==23671== by 0x8052DF7: SYSTEM_TOBJECT_$__NEWINSTANCE$$TOBJECT (in /home/jacques/Srf/Contabiliza/MemLeak)
==23671== by 0x805391D: SYSTEM_TINTERFACEDOBJECT_$__NEWINSTANCE$$TOBJECT (in /home/jacques/Srf/Contabiliza/MemLeak)
==23671== by 0x80F375A: ZGENERICSQLTOKEN_TZGENERICSQLTOKENIZER_$__CREATE$$TZGENERICSQLTOKENIZER (ZGenericSqlToken.pas:221)
==23671== by 0x81B74E5: ZDATASETUTILS_init (ZDatasetUtils.pas:1410)
==23671== by 0x8056E6C: fpc_initializeunits (in /home/jacques/Srf/Contabiliza/MemLeak)
==23671== by 0x8048AF3: main (MemLeak.lpr:12)
==23671==
==23671== LEAK SUMMARY:
==23671== definitely lost: 36 bytes in 1 blocks.
==23671== indirectly lost: 48 bytes in 2 blocks.
==23671== possibly lost: 286,646 bytes in 614 blocks.
==23671== still reachable: 0 bytes in 0 blocks.
==23671== suppressed: 0 bytes in 0 blocks.
==23671== Reachable blocks (those to which a pointer was found) are not shown.
==23671== To see them, rerun with: --show-reachable=yes

Any ideas ?


Jacques
jacques.bernardes
Fresh Boarder
Fresh Boarder
Posts: 10
Joined: 11.10.2006, 21:19

Post by jacques.bernardes »

The first valgrind error say

==6452== 84 (36 direct, 48 indirect) bytes in 1 blocks are definitely lost in loss record 1 of 5
==6452== at 0x40209DA: malloc (in /usr/lib/valgrind/x86-linux/vgpreload_memcheck.so)
==6452== by 0x8060214: (within /home/jacques/Srf/Contabiliza/MemLeak)
==6452== by 0x8058C78: SYSTEM_GETMEM$POINTER$LONGINT (in /home/jacques/Srf/Contabiliza/MemLeak)
==6452== by 0x8052DF7: SYSTEM_TOBJECT_$__NEWINSTANCE$$TOBJECT (in /home/jacques/Srf/Contabiliza/MemLeak)
==6452== by 0x805391D: SYSTEM_TINTERFACEDOBJECT_$__NEWINSTANCE$$TOBJECT (in /home/jacques/Srf/Contabiliza/MemLeak)
==6452== by 0x80D743C: ZDBCDBLIB_TZDBLIBDRIVER_$__CREATE$$TZDBLIBDRIVER (ZDbcDbLib.pas:148)
==6452== by 0x80D9CEB: ZDBCDBLIB_init (ZDbcDbLib.pas:740)
==6452== by 0x8056E6C: fpc_initializeunits (in /home/jacques/Srf/Contabiliza/MemLeak)
==6452== by 0x8048AF3: main (MemLeak.lpr:12)
=



Looking the file ZDbcDbLib.pas I can see the constructor for the object TZDBLibDriver. But I can't see the destructor. Is that correct ?

constructor TZDBLibDriver.Create;
begin
FMSSqlPlainDriver := TZDBLibMSSQL7PlainDriver.Create;
FSybasePlainDriver := TZDBLibSybaseASE125PlainDriver.Create;
end;


Developers, I need your help...

Jacques
Post Reply