From: Date: August 27 2005 10:51am Subject: bk commit into 4.1 tree (andrey:1.2397) BUG#12744 List-Archive: http://lists.mysql.com/internals/28927 X-Bug: 12744 Message-Id: <20050827085150.D7AD62E57F@andrey.hristov.com> Below is the list of changes that have just been committed into a local 4.1 repository of andrey. When andrey does a push these changes will be propagated to the main repository and, within 24 hours after the push, to the public repository. For information on how to access the public repository see http://dev.mysql.com/doc/mysql/en/installing-source-tree.html ChangeSet 1.2397 05/08/27 10:51:31 andrey@lmy004. +2 -0 fix for bug #12744 (MYSQL_STMT operations cause seg fault after connection reset) tests/mysql_client_test.c 1.157 05/08/27 10:51:25 andrey@lmy004. +32 -0 test for bug #12744 (MYSQL_STMT operations cause seg fault after connection reset) libmysql/libmysql.c 1.299 05/08/27 10:51:25 andrey@lmy004. +6 -0 stmt->mysql could be 0x0 if the connection has failed between prepare and execute or any other operation. thus if the user decides to use mysql_stmt_reset() we should not segfault. # This is a BitKeeper patch. What follows are the unified diffs for the # set of deltas contained in the patch. The rest of the patch, the part # that BitKeeper cares about, is below these diffs. # User: andrey # Host: lmy004. # Root: /work/mysql-4.1-clean --- 1.298/libmysql/libmysql.c 2005-08-04 12:22:34 +02:00 +++ 1.299/libmysql/libmysql.c 2005-08-27 10:51:25 +02:00 @@ -4628,6 +4628,12 @@ /* If statement hasnt been prepared there is nothing to reset */ if ((int) stmt->state < (int) MYSQL_STMT_PREPARE_DONE) DBUG_RETURN(0); + if (!stmt->mysql) + { + /* mysql can be reset in mysql_close called from mysql_reconnect */ + set_stmt_error(stmt, CR_SERVER_LOST, unknown_sqlstate); + DBUG_RETURN(1); + } mysql= stmt->mysql->last_used_con; int4store(buff, stmt->stmt_id); /* Send stmt id to server */ --- 1.156/tests/mysql_client_test.c 2005-08-17 21:38:42 +02:00 +++ 1.157/tests/mysql_client_test.c 2005-08-27 10:51:25 +02:00 @@ -11796,6 +11796,37 @@ DIE_UNLESS(res==1); } +static void test_bug12744() +{ + MYSQL_STMT *prep_stmt = NULL; + int rc; + myheader("test_bug12744"); + + prep_stmt= mysql_stmt_init(mysql); + rc= mysql_stmt_prepare(prep_stmt, "SELECT 1", 8); + DIE_UNLESS(rc==0); + + rc= mysql_kill(mysql, mysql_thread_id(mysql)); + DIE_UNLESS(rc==0); + + if (rc= mysql_stmt_execute(prep_stmt)) + { + if (rc= mysql_stmt_reset(prep_stmt)) + printf("OK!\n"); + else + { + printf("Error!"); + DIE_UNLESS(1==0); + } + } + else + { + fprintf(stderr, "expected error but no error occured\n"); + DIE_UNLESS(1==0); + } + rc= mysql_stmt_close(prep_stmt); +} + /* Bug#11718: query with function, join and order by returns wrong type */ @@ -12046,6 +12077,7 @@ { "test_bug8378", test_bug8378 }, { "test_bug9735", test_bug9735 }, { "test_bug11183", test_bug11183 }, + { "test_bug12744", test_bug12744 }, { "test_bug12001", test_bug12001 }, { "test_bug11718", test_bug11718 }, { 0, 0 }