From bbe121c0c9e334038b53745e7fb101db922ec57f Mon Sep 17 00:00:00 2001 From: "bell@sanja.is.com.ua" <> Date: Fri, 16 Jul 2004 15:20:51 +0300 Subject: [PATCH] memory leak removing --- .bzrignore | 1 + sql/sql_lex.h | 12 ++++++++++++ sql/sql_view.cc | 17 +++++++++++++++-- 3 files changed, 28 insertions(+), 2 deletions(-) diff --git a/.bzrignore b/.bzrignore index e653a6f4343..7e1a3545374 100644 --- a/.bzrignore +++ b/.bzrignore @@ -799,3 +799,4 @@ vio/test-ssl vio/test-sslclient vio/test-sslserver vio/viotest-ssl +libmysqld/sql_view.cc diff --git a/sql/sql_lex.h b/sql/sql_lex.h index 014a009f951..9e615d2ce9f 100644 --- a/sql/sql_lex.h +++ b/sql/sql_lex.h @@ -750,6 +750,18 @@ typedef struct st_lex bool only_view_structure(); } LEX; +struct st_lex_local: public st_lex +{ + static void *operator new(size_t size) + { + return (void*) sql_alloc((uint) size); + } + static void *operator new(size_t size, MEM_ROOT *mem_root) + { + return (void*) alloc_root(mem_root, (uint) size); + } + static void operator delete(void *ptr,size_t size) {} +}; void lex_init(void); void lex_free(void); diff --git a/sql/sql_view.cc b/sql/sql_view.cc index 7739cdf95bf..8d8e3d1d527 100644 --- a/sql/sql_view.cc +++ b/sql/sql_view.cc @@ -19,6 +19,7 @@ #include "sql_acl.h" #include "sql_select.h" #include "parse_file.h" +#include "sp.h" static int mysql_register_view(THD *thd, TABLE_LIST *view, enum_view_create_mode mode); @@ -523,9 +524,15 @@ mysql_make_view(File_parser *parser, TABLE_LIST *table) table->view_name.str= table->real_name; table->view_name.length= table->real_name_length; - //TODO: md5 test here and warning if it is differ + /*TODO: md5 test here and warning if it is differ */ - table->view= lex= thd->lex= new st_lex; + /* + TODO: TABLE mem root should be used here when VIEW will be stored in + TABLE cache + + now Lex placed in statement memory + */ + table->view= lex= thd->lex= (LEX*) new(&thd->mem_root) st_lex_local; lex_start(thd, (uchar*)table->query.str, table->query.length); mysql_init_query(thd, true); lex->select_lex.select_number= ++thd->select_number; @@ -563,6 +570,12 @@ mysql_make_view(File_parser *parser, TABLE_LIST *table) } if (!res && !thd->is_fatal_error) { + + /* move SP to main LEX */ + sp_merge_funs(old_lex, lex); + if (lex->spfuns.array.buffer) + hash_free(&lex->spfuns); + old_next= table->next_global; if ((table->next_global= lex->query_tables)) table->next_global->prev_global= &table->next_global;