MySQL 5.6.14 Source Code Document
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
sql_alloc_error_handler.cc
1 /* Copyright (c) 2010, 2011, Oracle and/or its affiliates. All rights reserved.
2 
3  This program is free software; you can redistribute it and/or modify
4  it under the terms of the GNU General Public License as published by
5  the Free Software Foundation; version 2 of the License.
6 
7  This program is distributed in the hope that it will be useful,
8  but WITHOUT ANY WARRANTY; without even the implied warranty of
9  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10  GNU General Public License for more details.
11 
12  You should have received a copy of the GNU General Public License
13  along with this program; if not, write to the Free Software Foundation,
14  51 Franklin Street, Suite 500, Boston, MA 02110-1335 USA */
15 
16 #include "log.h"
17 #include "sql_class.h"
18 #include "mysqld.h"
19 
20 extern "C" void sql_alloc_error_handler(void)
21 {
22  THD *thd= current_thd;
23  if (thd && !thd->is_error())
24  {
25  /*
26  This thread is Out Of Memory.
27 
28  An OOM condition is a fatal error. It should not be caught by error
29  handlers in stored procedures.
30 
31  Recording this SQL condition in the condition area could cause more
32  memory allocations, which in turn could raise more OOM conditions,
33  causing recursion in the error handling code itself. As a result,
34  my_error() should not be invoked, and the thread diagnostics area is
35  set to an error status directly.
36 
37  Note that Diagnostics_area::set_error_status() is safe, since it does
38  not call any memory allocation routines.
39 
40  The visible result for a client application will be:
41  - a query fails with an ER_OUT_OF_RESOURCES error, returned in the
42  error packet.
43  - SHOW ERROR/SHOW WARNINGS may be empty.
44  */
45  thd->get_stmt_da()->set_error_status(ER_OUT_OF_RESOURCES);
46  }
47 
48  /* Skip writing to the error log to avoid mtr complaints */
49  DBUG_EXECUTE_IF("simulate_out_of_memory", return;);
50 
51  sql_print_error("%s", ER(ER_OUT_OF_RESOURCES));
52 }