Skip to content

Commit 6c261ed

Browse files
committed
Bug #21066575 Correct failing multiple res.reset(pstmt->executeQuery());
Add unit test to test with valgrind Correct other bug test whci had memory leaks.
1 parent cf51692 commit 6c261ed

File tree

3 files changed

+75
-0
lines changed

3 files changed

+75
-0
lines changed

driver/nativeapi/mysql_native_statement_wrapper.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +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();
5960
api->stmt_close(stmt);
6061
}
6162
/* }}} */

test/unit/bugs/bugs.cpp

Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -579,12 +579,19 @@ void bugs::bug66871()
579579
res= stmt->getResultSet();
580580
ASSERT(res->next());
581581
ASSERT_EQUALS(res->getInt(1), 2);
582+
582583
}
583584
catch (::sql::SQLException & /*e*/)
584585
{
586+
delete res;
587+
delete stmt;
588+
585589
return; /* Everything is fine */
586590
}
587591

592+
delete res;
593+
delete stmt;
594+
588595
FAIL("Exception wasn't thrown by execute");
589596
}
590597

@@ -732,6 +739,70 @@ void bugs::bug66235()
732739
}
733740
}
734741

742+
void bugs::bug21066575()
743+
{
744+
logMsg("bug::bug21066575");
745+
try
746+
{
747+
748+
749+
stmt.reset(con->createStatement());
750+
stmt->execute("DROP TABLE IF EXISTS bug21066575");
751+
stmt->execute("CREATE TABLE bug21066575(txt text)");
752+
stmt->execute("INSERT INTO bug21066575(txt) VALUES('abc')");
753+
754+
pstmt.reset(con->prepareStatement("select * from bug21066575"));
755+
756+
for (int i = 0; i < 10; ++i)
757+
{
758+
res.reset(pstmt->executeQuery());
759+
res->next();
760+
ASSERT_EQUALS("abc", res->getString(1));
761+
}
762+
763+
stmt->execute("DROP TABLE IF EXISTS bug21066575_2");
764+
765+
stmt->execute("CREATE TABLE `bug21066575_2` (\
766+
`f1` longtext,\
767+
`id` int(11) NOT NULL AUTO_INCREMENT,\
768+
PRIMARY KEY (`id`)\
769+
) ENGINE=MyISAM AUTO_INCREMENT=3 DEFAULT CHARSET=latin1");
770+
771+
stmt->execute("insert into bug21066575_2(f1) values(repeat('f',1024000)),"
772+
"(repeat('f',1024000)),"
773+
"(repeat('f',1024000)),"
774+
"(repeat('f',1024000))");
775+
776+
//Detect with Valgrind if there are memory leaks
777+
for(int i= 0; i < 100; i++)
778+
{
779+
pstmt.reset(con->prepareStatement("select id, f1 from bug21066575_2"));
780+
781+
//pstmt->setInt(1, i);
782+
res.reset(pstmt->executeQuery());
783+
while (res->next()) {
784+
std::stringstream ss;
785+
ss << "id = " << res->getInt(1);
786+
ss << std::endl;
787+
ss << "f1 = " << res->getString(2);
788+
logMsg(ss.str().c_str());
789+
}
790+
}
791+
792+
res.reset();
793+
pstmt.reset();
794+
795+
sleep(1);
796+
797+
stmt->execute("DROP TABLE IF EXISTS test");
798+
}
799+
catch (sql::SQLException &e)
800+
{
801+
logErr(e.what());
802+
logErr("SQLState: " + std::string(e.getSQLState()));
803+
fail(e.what(), __FILE__, __LINE__);
804+
}
805+
}
735806

736807
} /* namespace regression */
737808
} /* namespace testsuite */

test/unit/bugs/bugs.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@ class bugs : public unit_fixture
6161
TEST_CASE(bug19938873_stmt);
6262
TEST_CASE(bug68523);
6363
TEST_CASE(bug66235);
64+
TEST_CASE(bug21066575);
6465
}
6566

6667
/**
@@ -103,6 +104,8 @@ class bugs : public unit_fixture
103104
void bug68523();
104105

105106
void bug66235();
107+
108+
void bug21066575();
106109
};
107110

108111
REGISTER_FIXTURE(bugs);

0 commit comments

Comments
 (0)