Description:
There is a memory leak in recently added fil_ibd_same_as_default_path() function which can be easily detected by Valgrind or ASAN when running some of MTR tests - for example main.partition_innodb_tablespace test.
How to repeat:
Make ASAN build of the server and run the ./mtr --mem partition_innodb_tablespace command. The test itself will succeed,
but post test error log check will detect memory leak report from LeakSanitizer:
==============================================================================
TEST NAME RESULT TIME (ms) COMMENT
------------------------------------------------------------------------------
[ 50%] main.partition_innodb_tablespace [ pass ] 4601
...
=================================================================
==430952==ERROR: LeakSanitizer: detected memory leaks
Direct leak of 51 byte(s) in 1 object(s) allocated from:
#0 0x7f26a16b4887 in __interceptor_malloc ../../../../src/libsanitizer/asan/asan_malloc_linux.cpp:145
#1 0x5dd5c470fce0 in ut::detail::malloc(unsigned long) ...src/git/mysql-server/storage/innobase/include/detail/ut/allocator_traits.h:72
#2 0x5dd5c470fd24 in ut::detail::Alloc_fn::malloc(unsigned long) ...src/git/mysql-server/storage/innobase/include/detail/ut/allocator_traits.h:89
#3 0x5dd5c471b558 in void* ut::detail::Alloc_fn::alloc<false>(unsigned long) ...src/git/mysql-server/storage/innobase/include/detail/ut/allocator_traits.h:98
#4 0x5dd5c471b5f6 in void* ut::detail::Alloc_pfs::alloc<false>(unsigned long, unsigned int) ...src/git/mysql-server/storage/innobase/include/detail/ut/alloc.h:276
#5 0x5dd5c471b714 in std::enable_if<ut::detail::Alloc_pfs::is_pfs_instrumented_v, void*>::type ut::detail::Alloc_<ut::detail::Alloc_pfs>::alloc<false, ut::detail::Alloc_pfs>(unsigned long, unsigned int) ...src/git/mysql-server/storage/innobase/include/detail/ut/alloc.h:439
#6 0x5dd5c471b7ad in ut::malloc_withkey(ut::PSI_memory_key_t, unsigned long) ...src/git/mysql-server/storage/innobase/include/ut0new.h:600
#7 0x5dd5c502f3a3 in mem_strdup ...src/git/mysql-server/storage/innobase/include/mem0mem.ic:495
#8 0x5dd5c503e4c5 in Fil_path::make(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, ib_file_suffix, bool) ...src/git/mysql-server/storage/innobase/fil/fil0fil.cc:4988
#9 0x5dd5c503ec21 in fil_ibd_same_as_default_path ...src/git/mysql-server/storage/innobase/fil/fil0fil.cc:9885
#10 0x5dd5c50427f3 in fil_tablespace_path_equals(unsigned int, char const*, unsigned long, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >*) ...src/git/mysql-server/storage/innobase/fil/fil0fil.cc:10083
...
Suggested fix:
fil_ibd_same_as_default_path() seems to forget to free memory allocated for default_path string on some of return paths from this function.
I will contribute simple fix for this.
Description: There is a memory leak in recently added fil_ibd_same_as_default_path() function which can be easily detected by Valgrind or ASAN when running some of MTR tests - for example main.partition_innodb_tablespace test. How to repeat: Make ASAN build of the server and run the ./mtr --mem partition_innodb_tablespace command. The test itself will succeed, but post test error log check will detect memory leak report from LeakSanitizer: ============================================================================== TEST NAME RESULT TIME (ms) COMMENT ------------------------------------------------------------------------------ [ 50%] main.partition_innodb_tablespace [ pass ] 4601 ... ================================================================= ==430952==ERROR: LeakSanitizer: detected memory leaks Direct leak of 51 byte(s) in 1 object(s) allocated from: #0 0x7f26a16b4887 in __interceptor_malloc ../../../../src/libsanitizer/asan/asan_malloc_linux.cpp:145 #1 0x5dd5c470fce0 in ut::detail::malloc(unsigned long) ...src/git/mysql-server/storage/innobase/include/detail/ut/allocator_traits.h:72 #2 0x5dd5c470fd24 in ut::detail::Alloc_fn::malloc(unsigned long) ...src/git/mysql-server/storage/innobase/include/detail/ut/allocator_traits.h:89 #3 0x5dd5c471b558 in void* ut::detail::Alloc_fn::alloc<false>(unsigned long) ...src/git/mysql-server/storage/innobase/include/detail/ut/allocator_traits.h:98 #4 0x5dd5c471b5f6 in void* ut::detail::Alloc_pfs::alloc<false>(unsigned long, unsigned int) ...src/git/mysql-server/storage/innobase/include/detail/ut/alloc.h:276 #5 0x5dd5c471b714 in std::enable_if<ut::detail::Alloc_pfs::is_pfs_instrumented_v, void*>::type ut::detail::Alloc_<ut::detail::Alloc_pfs>::alloc<false, ut::detail::Alloc_pfs>(unsigned long, unsigned int) ...src/git/mysql-server/storage/innobase/include/detail/ut/alloc.h:439 #6 0x5dd5c471b7ad in ut::malloc_withkey(ut::PSI_memory_key_t, unsigned long) ...src/git/mysql-server/storage/innobase/include/ut0new.h:600 #7 0x5dd5c502f3a3 in mem_strdup ...src/git/mysql-server/storage/innobase/include/mem0mem.ic:495 #8 0x5dd5c503e4c5 in Fil_path::make(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, ib_file_suffix, bool) ...src/git/mysql-server/storage/innobase/fil/fil0fil.cc:4988 #9 0x5dd5c503ec21 in fil_ibd_same_as_default_path ...src/git/mysql-server/storage/innobase/fil/fil0fil.cc:9885 #10 0x5dd5c50427f3 in fil_tablespace_path_equals(unsigned int, char const*, unsigned long, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >*) ...src/git/mysql-server/storage/innobase/fil/fil0fil.cc:10083 ... Suggested fix: fil_ibd_same_as_default_path() seems to forget to free memory allocated for default_path string on some of return paths from this function. I will contribute simple fix for this.