From 9c089b04b37a37261a6b143a7f5be6502b7f7b26 Mon Sep 17 00:00:00 2001 From: Sergei Golubchik Date: Tue, 9 Apr 2013 16:18:51 +0200 Subject: [PATCH] TABLE_SHARE::free_frm_image() method to free the memory allocated by the same allocator as in TABLE_SHARE::read_frm_image() --- sql/table.cc | 7 +++++++ sql/table.h | 26 ++++++++++++++++++++++++++ storage/archive/ha_archive.cc | 2 +- 3 files changed, 34 insertions(+), 1 deletion(-) diff --git a/sql/table.cc b/sql/table.cc index b311d8cb0a6..909ee241dcd 100644 --- a/sql/table.cc +++ b/sql/table.cc @@ -2137,6 +2137,13 @@ bool TABLE_SHARE::read_frm_image(const uchar **frm, size_t *len) } +void TABLE_SHARE::free_frm_image(const uchar *frm) +{ + if (frm) + my_free(const_cast(frm)); +} + + /* @brief Clear GET_FIXED_FIELDS_FLAG in all fields of a table diff --git a/sql/table.h b/sql/table.h index 6d20706cd92..2d929bfc41b 100644 --- a/sql/table.h +++ b/sql/table.h @@ -991,12 +991,38 @@ struct TABLE_SHARE uint actual_n_key_parts(THD *thd); LEX_CUSTRING *frm_image; ///< only during CREATE TABLE (@sa ha_create_table) + + /* + populates TABLE_SHARE from the table description in the binary frm image. + if 'write' is true, this frm image is also written into a corresponding + frm file, that serves as a persistent metadata cache to avoid + discovering the table over and over again + */ int init_from_binary_frm_image(THD *thd, bool write, const uchar *frm_image, size_t frm_length); + + /* + populates TABLE_SHARE from the table description, specified as the + complete CREATE TABLE sql statement. + if 'write' is true, this frm image is also written into a corresponding + frm file, that serves as a persistent metadata cache to avoid + discovering the table over and over again + */ int init_from_sql_statement_string(THD *thd, bool write, const char *sql, size_t sql_length); + /* + writes the frm image to an frm file, corresponding to this table + */ bool write_frm_image(const uchar *frm_image, size_t frm_length); + + /* + returns an frm image for this table. + the memory is allocated and must be freed later + */ bool read_frm_image(const uchar **frm_image, size_t *frm_length); + + /* frees the memory allocated in read_frm_image */ + void free_frm_image(const uchar *frm); }; diff --git a/storage/archive/ha_archive.cc b/storage/archive/ha_archive.cc index 9f164da3359..d18e46c08b1 100644 --- a/storage/archive/ha_archive.cc +++ b/storage/archive/ha_archive.cc @@ -764,7 +764,7 @@ int ha_archive::create(const char *name, TABLE *table_arg, if (!table_arg->s->read_frm_image(&frm_ptr, &frm_len)) { azwrite_frm(&create_stream, frm_ptr, frm_len); - my_free(const_cast(frm_ptr)); + table_arg->s->free_frm_image(frm_ptr); } if (create_info->comment.str)