From 3677dd5cb438e7b3ddb46a547f36fc2691c031a9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marko=20M=C3=A4kel=C3=A4?= Date: Fri, 5 Jun 2020 15:20:20 +0300 Subject: MDEV-22646: Fix a memory leak btr_search_sys_free(): Free btr_search_sys->hash_tables. The leak was introduced in commit ad2bf1129cfa85c00072b46e0355fe14bf69ee54. --- storage/innobase/btr/btr0sea.cc | 34 ++++++++++++++++++++++------------ 1 file changed, 22 insertions(+), 12 deletions(-) diff --git a/storage/innobase/btr/btr0sea.cc b/storage/innobase/btr/btr0sea.cc index 5614adc082a..ff1241740a4 100644 --- a/storage/innobase/btr/btr0sea.cc +++ b/storage/innobase/btr/btr0sea.cc @@ -203,23 +203,33 @@ btr_search_sys_create(ulint hash_size) } /** Frees the adaptive search system at a database shutdown. */ -void -btr_search_sys_free() +void btr_search_sys_free() { - ut_ad(btr_search_sys != NULL && btr_search_latches != NULL); + ut_ad(btr_search_sys); + ut_ad(btr_search_latches); - ut_free(btr_search_sys); - btr_search_sys = NULL; + if (btr_search_sys->hash_tables) + { + for (ulint i= 0; i < btr_ahi_parts; ++i) + { + mem_heap_free(btr_search_sys->hash_tables[i]->heap); + hash_table_free(btr_search_sys->hash_tables[i]); + } + ut_free(btr_search_sys->hash_tables); + } - /* Free all latches. */ - for (ulint i = 0; i < btr_ahi_parts; ++i) { + ut_free(btr_search_sys); + btr_search_sys= NULL; - rw_lock_free(btr_search_latches[i]); - ut_free(btr_search_latches[i]); - } + /* Free all latches. */ + for (ulint i= 0; i < btr_ahi_parts; ++i) + { + rw_lock_free(btr_search_latches[i]); + ut_free(btr_search_latches[i]); + } - ut_free(btr_search_latches); - btr_search_latches = NULL; + ut_free(btr_search_latches); + btr_search_latches= NULL; } /** Set index->ref_count = 0 on all indexes of a table. -- cgit v1.2.1