Skip to content

Fix bug 1604323 (pfs_instr_config_array elements not deallocated on s… #679

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jul 20, 2016
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Fix bug 1604323 (pfs_instr_config_array elements not deallocated on s…
…hutdown)

On several testcases (i.e. rpl_gtid_mode), LeakSanitizer diagnoses
missed memory deallocation:

=================================================================
==16675==ERROR: LeakSanitizer: detected memory leaks

Direct leak of 21 byte(s) in 1 object(s) allocated from:
    #0 0x7f17748fa54a in malloc (/usr/lib/x86_64-linux-gnu/libasan.so.2+0x9854a)
    #1 0xff7f7f in my_malloc /mnt/workspace/percona-server-5.6-asan-param/BUILD_TYPE/debug-asan/Host/ubuntu-xenial-64bit/mysys/my_malloc.c:38
    #2 0x1634b83 in add_pfs_instr_to_array(char const*, char const*) /mnt/workspace/percona-server-5.6-asan-param/BUILD_TYPE/debug-asan/Host/ubuntu-xenial-64bit/storage/perfschema/pfs_server.cc:251
    #3 0x58cccf in mysqld_get_one_option /mnt/workspace/percona-server-5.6-asan-param/BUILD_TYPE/debug-asan/Host/ubuntu-xenial-64bit/sql/mysqld.cc:9198
    #4 0x10256c6 in my_handle_options /mnt/workspace/percona-server-5.6-asan-param/BUILD_TYPE/debug-asan/Host/ubuntu-xenial-64bit/mysys_ssl/my_getopt.cc:817
    #5 0x1025c63 in handle_options /mnt/workspace/percona-server-5.6-asan-param/BUILD_TYPE/debug-asan/Host/ubuntu-xenial-64bit/mysys_ssl/my_getopt.cc:308
    #6 0x5963e5 in handle_early_options() /mnt/workspace/percona-server-5.6-asan-param/BUILD_TYPE/debug-asan/Host/ubuntu-xenial-64bit/sql/mysqld.cc:7263
    #7 0x5a35a3 in mysqld_main(int, char**) /mnt/workspace/percona-server-5.6-asan-param/BUILD_TYPE/debug-asan/Host/ubuntu-xenial-64bit/sql/mysqld.cc:5613
    #8 0x586aae in main /mnt/workspace/percona-server-5.6-asan-param/BUILD_TYPE/debug-asan/Host/ubuntu-xenial-64bit/sql/main.cc:25
    #9 0x7f17726cc82f in __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x2082f)

This class of errors is already attempted to suppress in
valgrind.supp. But these suppressions have been added to work around a
bug of racy PFS shutdown, which is not required anymore as
pfs_instr_config_array is deallocated exactly once since [1]. Thus,
free the elements of this array and remove related suppressions
instead.
  • Loading branch information
laurynas-biveinis committed Jul 19, 2016

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature.
commit 7daf372799bd43c542778375e156cc1a65b64dfb
66 changes: 0 additions & 66 deletions mysql-test/valgrind.supp
Original file line number Diff line number Diff line change
@@ -604,72 +604,6 @@
fun:lf_hash_search
}

{
missing shutdown_performance_schema 8
Memcheck:Leak
fun:malloc
fun:my_malloc
fun:_Z22add_pfs_instr_to_arrayPKcS0_
fun:mysqld_get_one_option
fun:my_handle_options
fun:handle_options
fun:_Z20handle_early_optionsv
}

{
missing shutdown_performance_schema 9
Memcheck:Leak
fun:malloc
fun:my_malloc
fun:init_dynamic_array2
fun:_Z25init_pfs_instrument_arrayv
fun:_Z11mysqld_mainiPPc
fun:main
}

{
missing shutdown_performance_schema 9a
Memcheck:Leak
fun:malloc
fun:my_malloc
fun:_Z22add_pfs_instr_to_arrayPKcS0_
fun:mysqld_get_one_option
fun:my_handle_options
fun:_Z20handle_early_optionsv
fun:_Z11mysqld_mainiPPc
}

# Same as shutdown_performance_schema 9,
# but the compiler/linker can sometime change the
# calls from:
# main()
# --> init_pfs_instrument_array()
# --> init_dynamic_array2()
# to:
# main()
# --> init_dynamic_array2()
# when building with optimizations.

{
missing shutdown_performance_schema 10
Memcheck:Leak
fun:malloc
fun:my_malloc
fun:init_dynamic_array2
fun:_Z11mysqld_mainiPPc
fun:main
}

{
missing shutdown_performance_schema 11
Memcheck:Leak
fun:malloc
fun:my_malloc
fun:init_dynamic_array2
fun:_Z11mysqld_mainiPPc
fun:(below main)
}

{
Bug 59874 Valgrind warning in InnoDB compression code
Memcheck:Cond
8 changes: 8 additions & 0 deletions storage/perfschema/pfs_server.cc
Original file line number Diff line number Diff line change
@@ -229,7 +229,15 @@ void cleanup_instrument_config()

/* Ignore if another thread has already deallocated the array */
if (my_atomic_cas32(&pfs_instr_config_state, &desired_state, PFS_INSTR_CONFIG_DEALLOCATED))
{
for (uint i= 0; i < pfs_instr_config_array.elements; i++)
{
PFS_instr_config* e;
get_dynamic(&pfs_instr_config_array, &e, i);
my_free(e);
}
delete_dynamic(&pfs_instr_config_array);
}
}

/**