Skip to content

Commit a996a55

Browse files
committed
Bug #21066575 Free resources when ReseultSet is deleted but only when not used by other object.
1 parent e60ace7 commit a996a55

File tree

3 files changed

+9
-9
lines changed

3 files changed

+9
-9
lines changed

driver/mysql_ps_resultset.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -253,6 +253,9 @@ void
253253
MySQL_Prepared_ResultSet::closeIntern()
254254
{
255255
CPP_ENTER("MySQL_Prepared_ResultSet::closeIntern");
256+
//if this is the only one, free result
257+
if (result_bind.use_count() == 2)
258+
proxy->stmt_free_result();
256259
is_valid = false;
257260
}
258261
/* }}} */

driver/nativeapi/mysql_native_statement_wrapper.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,8 +56,7 @@ MySQL_NativeStatementWrapper::MySQL_NativeStatementWrapper(::st_mysql_stmt * _st
5656
/* {{{ MySQL_NativeStatementWrapper::~MySQL_NativeStatementWrapper() */
5757
MySQL_NativeStatementWrapper::~MySQL_NativeStatementWrapper()
5858
{
59-
stmt_free_result();
60-
api->stmt_close(stmt);
59+
api->stmt_close(stmt);
6160
}
6261
/* }}} */
6362

test/unit/bugs/bugs.cpp

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -754,6 +754,8 @@ void bugs::bug21066575()
754754

755755
pstmt.reset(con->prepareStatement("select * from bug21066575"));
756756

757+
res.reset();
758+
757759
for (int i = 0; i < 10; ++i)
758760
{
759761
res.reset(pstmt->executeQuery());
@@ -774,7 +776,7 @@ void bugs::bug21066575()
774776
"(repeat('f',1024000)),"
775777
"(repeat('f',1024000))");
776778

777-
//Detect with Valgrind if there are memory leaks
779+
778780
for(int i= 0; i < 100; i++)
779781
{
780782
pstmt.reset(con->prepareStatement("select id, f1 from bug21066575_2"));
@@ -788,14 +790,10 @@ void bugs::bug21066575()
788790
ss << "f1 = " << res->getString(2);
789791
logMsg(ss.str().c_str());
790792
}
793+
//Detect if process frees ResultSet resources.
794+
res.reset();
791795
}
792796

793-
res.reset();
794-
pstmt.reset();
795-
796-
sleep(1);
797-
798-
stmt->execute("DROP TABLE IF EXISTS test");
799797
}
800798
catch (sql::SQLException &e)
801799
{

0 commit comments

Comments
 (0)