From 688fb6301c190a16987c91f5e14bdcc85d9b0ffa Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marko=20M=C3=A4kel=C3=A4?= Date: Fri, 21 Aug 2020 10:37:52 +0300 Subject: [PATCH] MDEV-23526 InnoDB leaks memory for some static objects MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit A leak of the contents of fil_system.ssd that was introduced in commit 10dd290b4b8b8b235c8cf42e100f0a4415629e79 (MDEV-17380) was caught by implementing SAFEMALLOC instrumentation of operator new. I did not try to find out how to make AddressSanitizer or Valgrind detect it. fil_system_t::close(): Clear fil_system.ssd. The leak was identified and a fix suggested by Michael Widenius and Vicențiu Ciorbaru. --- storage/innobase/fil/fil0fil.cc | 34 +++++++++++++++++++-------------- 1 file changed, 20 insertions(+), 14 deletions(-) diff --git a/storage/innobase/fil/fil0fil.cc b/storage/innobase/fil/fil0fil.cc index d47e9f3f5bf..5f263611cc1 100644 --- a/storage/innobase/fil/fil0fil.cc +++ b/storage/innobase/fil/fil0fil.cc @@ -1610,22 +1610,28 @@ void fil_system_t::create(ulint hash_size) void fil_system_t::close() { - ut_ad(this == &fil_system); - ut_a(!UT_LIST_GET_LEN(LRU)); - ut_a(unflushed_spaces.empty()); - ut_a(!UT_LIST_GET_LEN(space_list)); - ut_ad(!sys_space); - ut_ad(!temp_space); + ut_ad(this == &fil_system); + ut_a(!UT_LIST_GET_LEN(LRU)); + ut_a(unflushed_spaces.empty()); + ut_a(!UT_LIST_GET_LEN(space_list)); + ut_ad(!sys_space); + ut_ad(!temp_space); - if (is_initialised()) { - m_initialised = false; - hash_table_free(spaces); - spaces = NULL; - mutex_free(&mutex); - fil_space_crypt_cleanup(); - } + if (is_initialised()) + { + m_initialised= false; + hash_table_free(spaces); + spaces = nullptr; + mutex_free(&mutex); + fil_space_crypt_cleanup(); + } - ut_ad(!spaces); + ut_ad(!spaces); + +#ifdef UNIV_LINUX + ssd.clear(); + ssd.shrink_to_fit(); +#endif /* UNIV_LINUX */ } /*******************************************************************//**