From dfc38479ea034a024fbc8f991e6d9e66015225b7 Mon Sep 17 00:00:00 2001 From: "holyfoot/hf@mysql.com/hfmain.(none)" <> Date: Mon, 16 Jul 2007 19:08:07 +0500 Subject: [PATCH 1/2] Bug #29687 mysql_stmt_store_result memory leak in libmysqld In embedded server we use result->alloc to store field data for the result, but we didn't clean the result->alloc if the query returned an empty recordset. Cleaning for the empty recordset enabled --- libmysql/libmysql.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libmysql/libmysql.c b/libmysql/libmysql.c index 72bc4445d83..1a0aae414ed 100644 --- a/libmysql/libmysql.c +++ b/libmysql/libmysql.c @@ -4945,7 +4945,7 @@ static my_bool reset_stmt_handle(MYSQL_STMT *stmt, uint flags) Reset stored result set if so was requested or it's a part of cursor fetch. */ - if (result->data && (flags & RESET_STORE_RESULT)) + if (flags & RESET_STORE_RESULT) { /* Result buffered */ free_root(&result->alloc, MYF(MY_KEEP_PREALLOC)); From d0272fe1d5c79f1be669424e76dadd05a27db02f Mon Sep 17 00:00:00 2001 From: "holyfoot/hf@mysql.com/hfmain.(none)" <> Date: Thu, 19 Jul 2007 20:59:11 +0500 Subject: [PATCH 2/2] test case for memory leak added --- tests/mysql_client_test.c | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) diff --git a/tests/mysql_client_test.c b/tests/mysql_client_test.c index cb1561ad6f5..3a516545096 100644 --- a/tests/mysql_client_test.c +++ b/tests/mysql_client_test.c @@ -16271,6 +16271,38 @@ static void test_bug27592() } + +/* + Bug#29687 mysql_stmt_store_result memory leak in libmysqld +*/ + +static void test_bug29687() +{ + const int NUM_ITERATIONS= 40; + int i; + int rc; + MYSQL_STMT *stmt= NULL; + + DBUG_ENTER("test_bug29687"); + myheader("test_bug29687"); + + stmt= mysql_simple_prepare(mysql, "SELECT 1 FROM dual WHERE 0=2"); + DIE_UNLESS(stmt); + + for (i= 0; i < NUM_ITERATIONS; i++) + { + mysql_stmt_execute(stmt); + check_execute(stmt, rc); + mysql_stmt_store_result(stmt); + while (mysql_stmt_fetch(stmt)==0); + mysql_stmt_free_result(stmt); + } + + mysql_stmt_close(stmt); + DBUG_VOID_RETURN; +} + + /* Read and parse arguments and MySQL options from my.cnf */ @@ -16560,6 +16592,7 @@ static struct my_tests_st my_tests[]= { { "test_bug28505", test_bug28505 }, { "test_bug28934", test_bug28934 }, { "test_bug27592", test_bug27592 }, + { "test_bug29687", test_bug29687 }, { 0, 0 } };