Zeos 6.6.4 holding connection (tested with firebird and ado)

In this forum we will discuss things relating the ZEOSLib 6.6.x stable versions

Moderators: gto, EgonHugeist

Post Reply
personalsoft_fabiano
Fresh Boarder
Fresh Boarder
Posts: 15
Joined: 13.02.2009, 18:55
Location: Americana/SP

Zeos 6.6.4 holding connection (tested with firebird and ado)

Post by personalsoft_fabiano »

Hi, the code bellow doesn´t close the connection to the database after the end.
If i run on D2007 with "ReportMemoryLeaksOnShutdown := True", it reports some memory leaks.
If i use "ResultSet._Release" at the end of the block, it force the release of the ResultSet and others, disconnect from the database and doesn´t reports any leak.
Is it some known bug?

Regards,

Fabiano

var
Connection: IZConnection;
PreparedStatement: IZPreparedStatement;
ResultSet: IZResultSet;
begin
Connection := DriverManager.GetConnection('zdbc:firebird-2.0://127.0.0.1/teste?UID=sysdba;PWD=masterkey');
PreparedStatement := Connection.PrepareStatement('select * from emp1 where numemp1 = ?');
PreparedStatement.SetInt(1, 1);
ResultSet := PreparedStatement.ExecuteQueryPrepared;
end;
personalsoft_fabiano
Fresh Boarder
Fresh Boarder
Posts: 15
Joined: 13.02.2009, 18:55
Location: Americana/SP

Post by personalsoft_fabiano »

I think i have found the source of the problem:

There is a property called 'LastResultSet' on 'TZAbstractStatement'. The firebird driver (and i presume others, like ADO), when run a statement, stores the retrieved ResultSet in this property, what makes its reference count never drop to zero, and the ResultSet is never freed.

Looking at 'TZAbstractStatement' code, it seems 'LastResultSet' is used just to close the LastResultSet when another on is stored, or when the statement is destroyed. I don´t see why is it needed, if we can close the ResultSet in its destructor, and when it has no references, it will be destroyed (and closed)

Am i missing something here?

Regards,

Fabiano
personalsoft_fabiano
Fresh Boarder
Fresh Boarder
Posts: 15
Joined: 13.02.2009, 18:55
Location: Americana/SP

Post by personalsoft_fabiano »

After looking at this issue deeper, i see LastResultSet is usefull for drivers which can return multiple resultsets from execute statements, and it would be incorret to remove it.

And, in this specific case, the bug is in Firebird driver. The method TZInterbase6PreparedStatement.ExecuteQueryPrepared should never assign the ResultSet to LastResultSet, first because it already returns the resulset to the caller, and second because LastResultSet must be used just in TZInterbase6PreparedStatement.ExecutePrepared to retrive a possible generated ResultSet later.

How can i approve this fix and make it go to the source?

Regards,

Fabiano
seawolf
Zeos Dev Team *
Zeos Dev Team *
Posts: 385
Joined: 04.06.2008, 19:50
Contact:

Post by seawolf »

Do you wnat remove the selected line?
Have you tried doing some tests without it?

function TZInterbase6PreparedStatement.ExecuteQueryPrepared: IZResultSet;
begin
with FIBConnection do
begin
try
BindInParameters;

GetPlainDriver.isc_dsql_execute2(@FStatusVector, GetTrHandle, @StmtHandle,
GetDialect, FParamSQLData.GetData, nil);
CheckInterbase6Error(SQL);

if (StatementType in [stSelect, stExecProc])
and (SQLData.GetFieldCount <> 0) then
begin
if CursorName <> '' then
begin
Cursor := CursorName;
GetPlainDriver.isc_dsql_set_cursor_name(@FStatusVector,
@StmtHandle, PAnsiChar(Cursor), 0);
CheckInterbase6Error(SQL);
end;

Result := GetCachedResultSet(SQL, Self,
TZInterbase6ResultSet.Create(Self, SQL, StmtHandle, Cursor, SQLData, nil, FCachedBlob));
end
else
raise EZSQLException.Create(SCanNotRetrieveResultSetData);

LastResultSet := Result;
except
on E: Exception do
begin
FreeStatement(GetPlainDriver, StmtHandle, DSQL_close);
raise;
end;
end;
end;
inherited ExecuteQueryPrepared;
end;
seawolf
Zeos Dev Team *
Zeos Dev Team *
Posts: 385
Joined: 04.06.2008, 19:50
Contact:

Post by seawolf »

I removed the line and ran succesfully Zeos test projects.
So, in conclusion, I can say that line seems to be useless in that procedure
personalsoft_fabiano
Fresh Boarder
Fresh Boarder
Posts: 15
Joined: 13.02.2009, 18:55
Location: Americana/SP

Post by personalsoft_fabiano »

Seawolf, sorry not to answer earlier... I´m new to this forum, and i thought i would receive an e-mail if someone answer my posts...

Yes, i removed the line, analyzed the logic of the implementation, and i can say for sure there is no need for that line there.

Btw, i sent messages to some Zeos members offering to contribute, but had no responses until now. What should i do to contribute?

Regards,

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

Post by mdaems »

Hi, I did commit this change to SVN (Rev 613) a few days ago.

Only today I logged on to the forum again.


personalsoft_fabiano,

Your help and patches are very welcome. I don't know who you did send mails to. I hope it wasn't me. I can't remember seeing one.

Concerning mails from the forum : check your forum profile settings. Also check if your spam filter isn't cleaning the notifications.

Mark
Image
Post Reply