[fpc-devel] Mem-leak, where?
Joost van der Sluis
joost at cnoc.nl
Wed Sep 26 00:06:39 CEST 2007
Hi all,
About bug 9751. I don't understand where the leak comes from. Take this
code:
----
program testbug9751;
{$mode objfpc}{$H+}
uses
Classes, SysUtils, mysql41dyn;
var hmysql : PMYSQL;
begin
// InitialiseMysql; <-- remove the comment and the leakage is gone
repeat
InitialiseMysql;
hmysql := nil;
hmysql := mysql_init(hmysql);
// Comment the next line and the leakage is gone
HMySQL:=mysql_real_connect(HMySQL,PChar(''),PChar(''),Pchar(''),Nil,0,Nil,0);
mysql_close(hmysql);
ReleaseMysql;
until 1<0;
end.
----
This code leaks memory very fast. ;) First I thought that the
InitialiseMysql and ReleaseMysql were leaking. If you remove the first
comment, the leakage is gone. This is because the refcount of the
MySQL-library is increased, so that the library isn't loaded anymore
inside the loop.
But the strange thing is, that if you remove the mysql_real_connect, the
leakage is also gone.
Thus: the InitialiseMySQL and ReleaseMySQL (probably loadlibrary,
unloadlibrary and GetProcedureAddress) procedures are leaking memory,
but only if the library is called in between them. (not all functions,
but some of them)
Any ideas?
Joost.
More information about the fpc-devel
mailing list