utelle / wxsqlite3

wxSQLite3 - SQLite3 database wrapper for wxWidgets (including SQLite3 encryption extension)
http://utelle.github.io/wxsqlite3
Other
589 stars 178 forks source link

Memory leak in wxSQLite3Database::GetTable() #93

Closed bakcsizs closed 3 years ago

bakcsizs commented 3 years ago

Hello,

For each wxSQLite3Database::Interrupt() call, I get a memory leak with content "interrupted". As far as I could debug, it happens because in wxSQLite3Database::GetTable(), localError is not freed. Replacing throw wxSQLite3Exception(rc, wxString::FromUTF8(localError)); with const wxString err = wxString::FromUTF8(localError); sqlite3_free(localError); throw wxSQLite3Exception(rc, err); seems to solve the problem. But I'm not a wxsqlite3-insider, so I'm not sure this is the right solution. Thanks! Zsolt

utelle commented 3 years ago

Yes, you are right. Method wxSQLite3Database::GetTable can leak memory in case of an error. Thanks for reporting.

Your proposed fix is indeed correct. And at several places in wxSQLite3 memory retrieved from SQLite is freed in that way. Maybe this issue went undetected for such a long time, because the GetTable interface is not used very often. In fact, its usage is strongly discouraged.

bakcsizs commented 3 years ago

Yes, I was wondering myself why this wasn't noticed yet. Thanks for the explanation!