[Commits] 9002b96: MDEV-10034: Embedded server crashes on CREATE TABLE in PS protocol

Olaksandr Byelkin sanja at mariadb.com
Fri May 6 16:42:40 EEST 2016


revision-id: 9002b9696fb6d35ffb6a23f318e4c221674e6cd2 (mariadb-10.1.13-41-g9002b96)
parent(s): 1512078a7a56779d6fdd307a93187b61494de897
committer: Oleksandr Byelkin
timestamp: 2016-05-06 15:42:40 +0200
message:

MDEV-10034: Embedded server crashes on CREATE TABLE in PS protocol

alloc_root & free_root require current THD in case if they marked as thread specific (and stmt does).

---
 include/sql_common.h |  1 +
 libmysql/libmysql.c  |  3 +++
 libmysqld/lib_sql.cc | 10 +++++++++-
 sql-common/client.c  |  5 ++++-
 4 files changed, 17 insertions(+), 2 deletions(-)

diff --git a/include/sql_common.h b/include/sql_common.h
index 39b8ce1..a55db0f 100644
--- a/include/sql_common.h
+++ b/include/sql_common.h
@@ -74,6 +74,7 @@ typedef struct st_mysql_methods
   const char *(*read_statistics)(MYSQL *mysql);
   my_bool (*next_result)(MYSQL *mysql);
   int (*read_rows_from_cursor)(MYSQL_STMT *stmt);
+  void (*set_current_thd)(MYSQL *mysql);
 #endif
 } MYSQL_METHODS;
 
diff --git a/libmysql/libmysql.c b/libmysql/libmysql.c
index d5d673b..346505a 100644
--- a/libmysql/libmysql.c
+++ b/libmysql/libmysql.c
@@ -1623,6 +1623,7 @@ mysql_stmt_prepare(MYSQL_STMT *stmt, const char *query, ulong length)
     */
     stmt->bind_param_done= stmt->bind_result_done= FALSE;
     stmt->param_count= stmt->field_count= 0;
+    (*mysql->methods->set_current_thd)(mysql);
     free_root(&stmt->mem_root, MYF(MY_KEEP_PREALLOC));
     free_root(&stmt->extension->fields_mem_root, MYF(0));
 
@@ -1661,6 +1662,7 @@ mysql_stmt_prepare(MYSQL_STMT *stmt, const char *query, ulong length)
     or stmt->params when checking for existence of placeholders or
     result set.
   */
+  (*mysql->methods->set_current_thd)(mysql);
   if (!(stmt->params= (MYSQL_BIND *) alloc_root(&stmt->mem_root,
 						sizeof(MYSQL_BIND)*
                                                 (stmt->param_count +
@@ -4696,6 +4698,7 @@ my_bool STDCALL mysql_stmt_close(MYSQL_STMT *stmt)
   int rc= 0;
   DBUG_ENTER("mysql_stmt_close");
 
+  (*mysql->methods->set_current_thd)(mysql);
   free_root(&stmt->result.alloc, MYF(0));
   free_root(&stmt->mem_root, MYF(0));
   free_root(&stmt->extension->fields_mem_root, MYF(0));
diff --git a/libmysqld/lib_sql.cc b/libmysqld/lib_sql.cc
index a313c62..11401a2 100644
--- a/libmysqld/lib_sql.cc
+++ b/libmysqld/lib_sql.cc
@@ -55,6 +55,13 @@ extern "C" void unireg_clear(int exit_code)
   DBUG_VOID_RETURN;
 }
 
+
+void emb_set_current_thd(MYSQL *mysql)
+{
+  THD *thd= (THD*) mysql->thd;
+  thd->store_globals();
+}
+
 /*
   Wrapper error handler for embedded server to call client/server error 
   handler based on whether thread is in client/server context
@@ -469,7 +476,8 @@ MYSQL_METHODS embedded_methods=
   emb_free_embedded_thd,
   emb_read_statistics,
   emb_read_query_result,
-  emb_read_rows_from_cursor
+  emb_read_rows_from_cursor,
+  emb_set_current_thd
 };
 
 /*
diff --git a/sql-common/client.c b/sql-common/client.c
index 9904719..4538267 100644
--- a/sql-common/client.c
+++ b/sql-common/client.c
@@ -1851,6 +1851,8 @@ static int ssl_verify_server_cert(Vio *vio, const char* server_hostname, const c
 #endif /* HAVE_OPENSSL */
 
 
+void cli_do_nothing(MYSQL *mysql __attribute__((unused))){}
+
 /*
   Note that the mysql argument must be initialized with mysql_init()
   before calling mysql_real_connect !
@@ -1882,7 +1884,8 @@ static MYSQL_METHODS client_methods=
   NULL,                                        /* free_embedded_thd */
   cli_read_statistics,                         /* read_statistics */
   cli_read_query_result,                       /* next_result */
-  cli_read_binary_rows                         /* read_rows_from_cursor */
+  cli_read_binary_rows,                        /* read_rows_from_cursor */
+  cli_do_nothing
 #endif
 };
 


More information about the commits mailing list