Page 1 of 1

Resource leak in wxsqlite3.cpp

Posted: Mon Sep 07, 2009 6:43 am
by Vadim
Hi,
Class wxSQLite3Statement (wxsqlite3.cpp) has resource leak in its operator=().
The code does not release m_stmt before assigning new value to one.

wxSQLite3Statement& wxSQLite3Statement::operator=(const wxSQLite3Statement& statement)
{
m_db = statement.m_db;
m_stmt = statement.m_stmt; // RESOURCE LEAK, must be called sqlite3_finalize(m_stmt) first!!!
// Only one object can own prepared statement
const_cast<wxSQLite3Statement&>(statement).m_stmt = 0;
return *this;
}


Take a look at similar right code.

wxSQLite3ResultSet& wxSQLite3ResultSet::operator=(const wxSQLite3ResultSet& resultSet)
{
try
{
Finalize(); // free m_stmt if owns
}
catch (...)
{
}
m_stmt = resultSet.m_stmt;
// Only one object can own the statement
const_cast<wxSQLite3ResultSet&>(resultSet).m_stmt = 0;
m_eof = resultSet.m_eof;
m_first = resultSet.m_first;
m_cols = resultSet.m_cols;
m_ownStmt = resultSet.m_ownStmt;
return *this;
}

Re: Resource leak in wxsqlite3.cpp

Posted: Mon Sep 07, 2009 6:47 am
by Vadim
The latest release of wxSQLite3 is 1.9.5, wxcode.sourceforge.net/components/wxsqlite3.
I think it would be better to update sources of wxSQLite3 in our project.

Re: Resource leak in wxsqlite3.cpp

Posted: Mon Sep 07, 2009 6:54 am
by Vadim
This bug still presents in the latest version :(
I have registered this bug on bugtracker of project.

Re: Resource leak in wxsqlite3.cpp

Posted: Wed Sep 09, 2009 6:40 am
by Vadim
The bug has fixed by author of wxSQLite3.
http://sourceforge.net/tracker/?func=de ... tid=462816

Re: Resource leak in wxsqlite3.cpp

Posted: Wed Sep 09, 2009 9:35 pm
by madhan
Good Find Vadim.

Do you have files you can supply to replace the ones in the sources?

Re: Resource leak in wxsqlite3.cpp

Posted: Thu Sep 10, 2009 8:51 am
by Vadim
I have downloaded the latest version of wxsqlite3. Surely, I can update sources. But the distribution of wxsqlite3-1.9.5 contains wxsqlite3.h wxsqlite3def.h wxsqlite3dyn.h wxsqlite3opt.h.
In mmex I see include\wx and include\wxsqlite3_secure. Which of them should I update? Or update both?

Re: Resource leak in wxsqlite3.cpp

Posted: Mon Sep 14, 2009 11:29 am
by Vadim
wxsqlite3 sources upgraded to the latest version (currently 1.9.5).
Committed revision 412.