From: Nirbhay Choubey Date: October 22 2012 1:58pm Subject: bzr push into mysql-trunk branch (nirbhay.choubey:4789 to 4790) Bug#14742760 List-Archive: http://lists.mysql.com/commits/145102 X-Bug: 14742760 Message-Id: <20121022135851.32159.3103.4790@Nirbhay-lenovo> MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit 4790 Nirbhay Choubey 2012-10-22 [merge] Merge of patch for bug#14742760 from mysql-5.6. modified: client/mysql.cc include/my_sys.h sql/sql_insert.cc 4789 Tanjot Uppal 2012-10-22 [merge] null merge === modified file 'client/mysql.cc' --- a/client/mysql.cc 2012-10-09 17:24:22 +0000 +++ b/client/mysql.cc 2012-10-22 13:56:18 +0000 @@ -62,6 +62,9 @@ static char *server_version= NULL; /* Array of options to pass to libemysqld */ #define MAX_SERVER_ARGS 64 +/* Maximum memory limit that can be claimed by alloca(). */ +#define MAX_ALLOCA_SIZE 512 + #include "sql_string.h" extern "C" { @@ -3711,8 +3714,10 @@ print_table_data(MYSQL_RES *result) MYSQL_ROW cur; MYSQL_FIELD *field; bool *num_flag; + size_t sz; - num_flag=(bool*) my_alloca(sizeof(bool)*mysql_num_fields(result)); + sz= sizeof(bool) * mysql_num_fields(result); + num_flag= (bool *) my_safe_alloca(sz, MAX_ALLOCA_SIZE); if (column_types_flag) { print_field_types(result); @@ -3813,7 +3818,7 @@ print_table_data(MYSQL_RES *result) (void) tee_fputs("\n", PAGER); } tee_puts((char*) separator.ptr(), PAGER); - my_afree((uchar*) num_flag); + my_safe_afree((bool *) num_flag, sz, MAX_ALLOCA_SIZE); } /** === modified file 'include/my_sys.h' --- a/include/my_sys.h 2012-10-09 17:24:22 +0000 +++ b/include/my_sys.h 2012-10-22 13:56:18 +0000 @@ -159,6 +159,22 @@ extern void *my_memdup(const void *from, extern char *my_strdup(const char *from,myf MyFlags); extern char *my_strndup(const char *from, size_t length, myf MyFlags); + +/* + Switch to my_malloc() if the memory block to be allocated is bigger than + max_alloca_sz. +*/ +#ifndef HAVE_ALLOCA +#define my_safe_alloca(size, max_alloca_sz) my_alloca(size) +#define my_safe_afree(ptr, size, max_alloca_sz) my_afree(ptr) +#else +#define my_safe_alloca(size, max_alloca_sz) ((size <= max_alloca_sz) ? \ + my_alloca(size) : \ + my_malloc(size, MYF(0))) +#define my_safe_afree(ptr, size, max_alloca_sz) if (size > max_alloca_sz) \ + my_free(ptr) +#endif /* #ifndef HAVE_ALLOCA */ + #if !defined(DBUG_OFF) || defined(HAVE_VALGRIND) /** Put bad content in memory to be sure it will segfault if dereferenced. === modified file 'sql/sql_insert.cc' --- a/sql/sql_insert.cc 2012-09-22 17:12:32 +0000 +++ b/sql/sql_insert.cc 2012-10-22 13:56:18 +0000 @@ -102,16 +102,6 @@ static void unlink_blobs(register TABLE #endif static bool check_view_insertability(THD *thd, TABLE_LIST *view); -/* Define to force use of my_malloc() if the allocated memory block is big */ - -#ifndef HAVE_ALLOCA -#define my_safe_alloca(size, min_length) my_alloca(size) -#define my_safe_afree(ptr, size, min_length) my_afree(ptr) -#else -#define my_safe_alloca(size, min_length) ((size <= min_length) ? my_alloca(size) : my_malloc(size,MYF(0))) -#define my_safe_afree(ptr, size, min_length) if (size > min_length) my_free(ptr) -#endif - /* Check that insert/update fields are from the same single table of a view. No bundle (reason: useless for push emails).