summaryrefslogtreecommitdiff
path: root/sql/thr_malloc.cc
diff options
context:
space:
mode:
Diffstat (limited to 'sql/thr_malloc.cc')
-rw-r--r--sql/thr_malloc.cc89
1 files changed, 46 insertions, 43 deletions
diff --git a/sql/thr_malloc.cc b/sql/thr_malloc.cc
index 43338e4c180..3bc90cf5ccd 100644
--- a/sql/thr_malloc.cc
+++ b/sql/thr_malloc.cc
@@ -1,5 +1,5 @@
-/* Copyright (c) 2000, 2001, 2003, 2004, 2006, 2008 MySQL AB, 2008, 2009 Sun Microsystems, Inc.
- Use is subject to license terms.
+/*
+ Copyright (c) 2000, 2010, Oracle and/or its affiliates. All rights reserved.
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
@@ -12,7 +12,8 @@
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
- Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */
+ Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
+*/
/* Mallocs for used in threads */
@@ -22,35 +23,38 @@
extern "C" {
void sql_alloc_error_handler(void)
{
- sql_print_error("%s", ER(ER_OUT_OF_RESOURCES));
-
- THD *thd=current_thd;
+ THD *thd= current_thd;
if (thd)
{
- /*
- This thread is Out Of Memory.
- An OOM condition is a fatal error.
- It should not be caught by error handlers in stored procedures.
- Also, recording that SQL condition in the condition area could
- cause more memory allocations, which in turn could raise more
- OOM conditions, causing recursion in the error handling code itself.
- As a result, my_error() should not be invoked, and the
- thread diagnostics area is set to an error status directly.
- The visible result for a client application will be:
- - a query fails with an ER_OUT_OF_RESOURCES error,
- returned in the error packet.
- - SHOW ERROR/SHOW WARNINGS may be empty.
- */
-
- NET *net= &thd->net;
- thd->fatal_error();
- if (!net->last_error[0]) // Return only first message
+ if (! thd->is_error())
{
- strmake(net->last_error, ER(ER_OUT_OF_RESOURCES),
- sizeof(net->last_error)-1);
- net->last_errno= ER_OUT_OF_RESOURCES;
+ /*
+ This thread is Out Of Memory.
+ An OOM condition is a fatal error.
+ It should not be caught by error handlers in stored procedures.
+ Also, recording that SQL condition in the condition area could
+ cause more memory allocations, which in turn could raise more
+ OOM conditions, causing recursion in the error handling code itself.
+ As a result, my_error() should not be invoked, and the
+ thread diagnostics area is set to an error status directly.
+ Note that Diagnostics_area::set_error_status() is safe,
+ since it does not call any memory allocation routines.
+ The visible result for a client application will be:
+ - a query fails with an ER_OUT_OF_RESOURCES error,
+ returned in the error packet.
+ - SHOW ERROR/SHOW WARNINGS may be empty.
+ */
+ thd->main_da.set_error_status(thd,
+ ER_OUT_OF_RESOURCES,
+ ER(ER_OUT_OF_RESOURCES));
}
}
+
+ /* Skip writing to the error log to avoid mtr complaints */
+ DBUG_EXECUTE_IF("simulate_out_of_memory", return;);
+
+ sql_print_error("%s", ER(ER_OUT_OF_RESOURCES));
+
}
}
@@ -61,26 +65,25 @@ void init_sql_alloc(MEM_ROOT *mem_root, uint block_size, uint pre_alloc)
}
-gptr sql_alloc(uint Size)
+void *sql_alloc(size_t Size)
{
MEM_ROOT *root= *my_pthread_getspecific_ptr(MEM_ROOT**,THR_MALLOC);
- char *ptr= (char*) alloc_root(root,Size);
- return ptr;
+ return alloc_root(root,Size);
}
-gptr sql_calloc(uint size)
+void *sql_calloc(size_t size)
{
- gptr ptr;
+ void *ptr;
if ((ptr=sql_alloc(size)))
- bzero((char*) ptr,size);
+ bzero(ptr,size);
return ptr;
}
char *sql_strdup(const char *str)
{
- uint len=(uint) strlen(str)+1;
+ size_t len= strlen(str)+1;
char *pos;
if ((pos= (char*) sql_alloc(len)))
memcpy(pos,str,len);
@@ -88,7 +91,7 @@ char *sql_strdup(const char *str)
}
-char *sql_strmake(const char *str,uint len)
+char *sql_strmake(const char *str, size_t len)
{
char *pos;
if ((pos= (char*) sql_alloc(len+1)))
@@ -100,10 +103,10 @@ char *sql_strmake(const char *str,uint len)
}
-gptr sql_memdup(const void *ptr,uint len)
+void* sql_memdup(const void *ptr, size_t len)
{
- char *pos;
- if ((pos= (char*) sql_alloc(len)))
+ void *pos;
+ if ((pos= sql_alloc(len)))
memcpy(pos,ptr,len);
return pos;
}
@@ -113,17 +116,17 @@ void sql_element_free(void *ptr __attribute__((unused)))
-char *sql_strmake_with_convert(const char *str, uint32 arg_length,
+char *sql_strmake_with_convert(const char *str, size_t arg_length,
CHARSET_INFO *from_cs,
- uint32 max_res_length,
- CHARSET_INFO *to_cs, uint32 *result_length)
+ size_t max_res_length,
+ CHARSET_INFO *to_cs, size_t *result_length)
{
char *pos;
- uint32 new_length= to_cs->mbmaxlen*arg_length;
+ size_t new_length= to_cs->mbmaxlen*arg_length;
max_res_length--; // Reserve place for end null
set_if_smaller(new_length, max_res_length);
- if (!(pos= sql_alloc(new_length+1)))
+ if (!(pos= (char*) sql_alloc(new_length+1)))
return pos; // Error
if ((from_cs == &my_charset_bin) || (to_cs == &my_charset_bin))