=== modified file 'sql/protocol.cc'
--- sql/protocol.cc	2013-03-27 22:41:02 +0000
+++ sql/protocol.cc	2013-05-31 10:37:22 +0000
@@ -1546,14 +1546,14 @@
   /* Restore THD::server_status. */
   thd->server_status&= ~SERVER_PS_OUT_PARAMS;
 
+  /* Send EOF-packet. */
+  net_send_eof(thd, thd->server_status, 0);
+
   /*
     Reset SERVER_MORE_RESULTS_EXISTS bit, because this is the last packet
     for sure.
   */
   thd->server_status&= ~SERVER_MORE_RESULTS_EXISTS;
 
-  /* Send EOF-packet. */
-  net_send_eof(thd, thd->server_status, 0);
-
   return FALSE;
 }

=== modified file 'tests/mysql_client_test.c'
--- tests/mysql_client_test.c	2013-04-15 13:09:22 +0000
+++ tests/mysql_client_test.c	2013-05-31 11:44:55 +0000
@@ -18850,6 +18850,76 @@
   myquery(rc);
 }
 
+static void test_ps_sp_out_params()
+{
+  MYSQL *my;
+  MYSQL_STMT *stmt;
+  MYSQL_BIND bind[1];
+  char buffer[20];
+  int status, rc;
+
+  myheader("test_ps_sp_out_params");
+  my= mysql_client_init(NULL);
+
+  if (!mysql_real_connect(my, opt_host, opt_user,
+                               opt_password, current_db, opt_port,
+                               opt_unix_socket, CLIENT_MULTI_RESULTS))
+    DIE("mysql_real_connect failed");
+
+  rc= mysql_query(my, "DROP PROCEDURE IF EXISTS p1");
+  myquery(rc);
+
+  rc= mysql_query(my,
+    "CREATE PROCEDURE p1(OUT out_param VARCHAR(19)) "
+    "BEGIN"
+    " SELECT 'foo' FROM DUAL;"
+    " SET out_param='foo';"
+    " SELECT 'foo' FROM DUAL;"
+    "END");
+  myquery(rc);
+
+  stmt= mysql_stmt_init(my);
+
+  rc= mysql_stmt_prepare(stmt, "CALL P1(?)", 10);
+  DIE_UNLESS(rc==0);
+
+  DIE_UNLESS(mysql_stmt_param_count(stmt) == 1);
+
+  memset(bind, 0, sizeof(MYSQL_BIND));
+  bind[0].buffer= buffer;
+  bind[0].buffer_length= sizeof(buffer);
+  bind[0].buffer_type= MYSQL_TYPE_STRING;
+
+  mysql_stmt_bind_param(stmt, bind);
+
+  rc= mysql_stmt_execute(stmt);
+  check_execute(stmt, rc);
+
+  do {
+    if (mysql_stmt_field_count(stmt))
+    {
+      /* since server sends a status packet at the end,
+         there must follow at least one additional packet */
+      DIE_UNLESS(mysql_more_results(stmt->mysql));
+
+      mysql_stmt_bind_result(stmt, bind);
+
+      rc= mysql_stmt_fetch(stmt);
+      DIE_UNLESS(rc== 0);
+
+      DIE_UNLESS(strcmp(buffer, "foo") == 0);
+    }
+    status= mysql_stmt_next_result(stmt);
+  } while (status == 0);
+
+  rc= mysql_stmt_reset(stmt);
+  DIE_UNLESS(rc== 0);
+
+  mysql_stmt_close(stmt);
+  mysql_close(my);
+
+  printf("end\n");
+}
 
 static struct my_tests_st my_tests[]= {
   { "disable_query_logs", disable_query_logs },
@@ -19115,6 +19185,7 @@
   { "test_progress_reporting", test_progress_reporting },
   { "test_bug11754979", test_bug11754979 },
   { "test_bug13001491", test_bug13001491 },
+  { "test_ps_sp_out_params", test_ps_sp_out_params },
   { 0, 0 }
 };
 

