null+****@clear*****
null+****@clear*****
2012年 1月 10日 (火) 11:45:27 JST
Kouhei Sutou 2012-01-10 11:45:27 +0900 (Tue, 10 Jan 2012) New Revision: bae8e77d60d52e44c9306ebd3d4f901b37dd4b1a Log: [wrapper] fix a memory leak. Reported by montywi. Thanks!!! Modified files: ha_mroonga.cc ha_mroonga.h Modified: ha_mroonga.cc (+49 -19) =================================================================== --- ha_mroonga.cc 2012-01-09 22:46:26 +0900 (a980cdb) +++ ha_mroonga.cc 2012-01-10 11:45:27 +0900 (a5cddeb) @@ -3319,26 +3319,7 @@ int ha_mroonga::wrapper_close() int ha_mroonga::storage_close() { MRN_DBUG_ENTER_METHOD(); - uint i; - uint n_keys = table->s->keys; - uint pkey_nr = table->s->primary_key; - for (i = 0; i < n_keys; i++) { - free(key_min[i]); - free(key_max[i]); - if (i == pkey_nr) { - continue; - } - grn_obj_unlink(ctx, grn_index_tables[i]); - } grn_obj_unlink(ctx, grn_table); - - if (grn_index_tables != NULL) { - free(grn_index_tables); - free(grn_index_columns); - free(key_min); - free(key_max); - } - free(grn_columns); DBUG_RETURN(0); } @@ -3348,6 +3329,9 @@ int ha_mroonga::close() int error = 0; THD *thd = ha_thd(); MRN_DBUG_ENTER_METHOD(); + + clear_indexes(); + if (share->wrapper_mode) { error = wrapper_close(); @@ -6454,6 +6438,52 @@ void ha_mroonga::clear_search_result_geo() DBUG_VOID_RETURN; } +void ha_mroonga::clear_indexes() +{ + MRN_DBUG_ENTER_METHOD(); + uint n_keys = table->s->keys; + uint pkey_nr = table->s->primary_key; + + for (uint i = 0; i < n_keys; i++) { + if (i != pkey_nr) { + if (grn_index_tables) { + grn_obj_unlink(ctx, grn_index_tables[i]); + } + if (grn_index_columns) { + grn_obj_unlink(ctx, grn_index_columns[i]); + } + } + if (key_min) { + free(key_min[i]); + } + if (key_max) { + free(key_max[i]); + } + } + + if (grn_index_tables) { + free(grn_index_tables); + grn_index_tables = NULL; + } + + if (grn_index_columns) { + free(grn_index_columns); + grn_index_columns = NULL; + } + + if (key_min) { + free(key_min); + key_min = NULL; + } + + if (key_max) { + free(key_max); + key_max = NULL; + } + + DBUG_VOID_RETURN; +} + grn_obj *ha_mroonga::find_tokenizer(const char *name, int name_length) { MRN_DBUG_ENTER_METHOD(); Modified: ha_mroonga.h (+1 -0) =================================================================== --- ha_mroonga.h 2012-01-09 22:46:26 +0900 (354aae5) +++ ha_mroonga.h 2012-01-10 11:45:27 +0900 (fbdc0ce) @@ -385,6 +385,7 @@ private: void clear_cursor_geo(); void clear_search_result(); void clear_search_result_geo(); + void clear_indexes(); grn_obj *find_tokenizer(const char *name, int name_length); int wrapper_get_next_record(uchar *buf); int storage_get_next_record(uchar *buf);