diff --git a/mysql-test/t/binlog.test b/mysql-test/t/binlog.test
index 42dd4ee629947d8b850dfce9a2e1814a2cd2dd9f..1063940d37806778eddb09e509fee3f6993c5b88 100644
--- a/mysql-test/t/binlog.test
+++ b/mysql-test/t/binlog.test
@@ -19,7 +19,7 @@ begin;
 insert t2 values (5);
 commit;
 # first COMMIT must be Query_log_event, second - Xid_log_event
---replace_result "xid=19" "xid=12"
+--replace_result "xid=21" "xid=12"
 --replace_column 2 # 5 #
 show binlog events from 98;
 drop table t1,t2;
@@ -41,7 +41,7 @@ while ($1)
 --enable_query_log
 commit;
 drop table t1;
---replace_result "xid=30" "xid=19"
+--replace_result "xid=32" "xid=19"
 --replace_column 2 # 5 #
 show binlog events in 'master-bin.000001' from 98;
 --replace_column 2 # 5 #
diff --git a/sql/sql_db.cc b/sql/sql_db.cc
index 357d2d5a21f32fb2a766a356f005397817b484d0..09412bfe401228f644a5a311b8c733aeff0a5fcf 100644
--- a/sql/sql_db.cc
+++ b/sql/sql_db.cc
@@ -1109,6 +1109,9 @@ bool mysql_change_db(THD *thd, const char *name, bool no_access_check)
   DBUG_ENTER("mysql_change_db");
   DBUG_PRINT("enter",("name: '%s'",name));
 
+  LINT_INIT(db_length);
+  LINT_INIT(db_access);
+
   /* dbname can only be NULL if malloc failed */
   if (!dbname || !(db_length= strlen(dbname)))
   {
@@ -1126,7 +1129,7 @@ bool mysql_change_db(THD *thd, const char *name, bool no_access_check)
   if (check_db_name(dbname))
   {
     my_error(ER_WRONG_DB_NAME, MYF(0), dbname);
-    x_free(dbname);
+    my_free(dbname, MYF(0));
     DBUG_RETURN(1);
   }
   DBUG_PRINT("info",("Use database: %s", dbname));
@@ -1176,8 +1179,6 @@ end:
     x_free(thd->db);
   if (dbname && dbname[0] == 0)
   {
-    if (!(thd->slave_thread))
-      x_free(dbname);
     thd->db= NULL;
     thd->db_length= 0;
   }
diff --git a/tests/mysql_client_test.c b/tests/mysql_client_test.c
index c265375a263a1802040e91141af263965ecdd248..f58804505d444b69ff7fc5b3738aff226a4d6e75 100644
--- a/tests/mysql_client_test.c
+++ b/tests/mysql_client_test.c
@@ -14724,9 +14724,9 @@ static void test_bug12744()
 
   mysql_close(mysql);
 
-  if (rc= mysql_stmt_execute(prep_stmt))
+  if ((rc= mysql_stmt_execute(prep_stmt)))
   {
-    if (rc= mysql_stmt_reset(prep_stmt))
+    if ((rc= mysql_stmt_reset(prep_stmt)))
       printf("OK!\n");
     else
     {