Commit d279c11e authored by Mateusz Loskot's avatar Mateusz Loskot

Fix memory leak of statement backend (issue #67)

The leak has been confirmed usign memory debugger. Applied fix suggested
by Evgeny Barabanov to perform allocated statement clean up if exception
is thrown from prepare() method.
parent b29861ee
......@@ -55,7 +55,15 @@ statement_impl::statement_impl(prepare_temp_type const & prep)
// prepare the statement
query_ = prepInfo->get_query();
prepare(query_);
try
{
prepare(query_);
}
catch(...)
{
clean_up();
throw;
}
define_and_bind();
}
......
......@@ -303,6 +303,7 @@ public:
test28();
test29();
test30();
test_issue67();
}
private:
......@@ -3490,6 +3491,28 @@ void test30()
#endif // HAVE_BOOST
}
// issue 67 - Allocated statement backend memory leaks on exception
// If the test runs under memory debugger and it passes, then
// soci::details::statement_impl::backEnd_ must not leak
void test_issue67()
{
session sql(backEndFactory_, connectString_);
auto_table_creator tableCreator(tc_.table_creator_1(sql));
{
try
{
rowset<row> rs1 = (sql.prepare << "select * from soci_testX");
assert(!"exception expected");
}
catch (soci_error const &e)
{
(void)e;
assert("expected exception caught");
std::cout << "test_issue67 passed - check memory debugger output for leaks" << std::endl;
}
}
}
}; // class common_tests
} // namespace tests
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment