Skip to content

Commit

Permalink
Fix memory leak in perfschema instrument array
Browse files Browse the repository at this point in the history
Summary:
Fix yet another memory leak reported by ASAN, in perfschema dynamic array of
instrument config.

LeakSanitizer reported:

  ==1556117==ERROR: LeakSanitizer: detected memory leaks

  Direct leak of 21 byte(s) in 1 object(s) allocated from:
      #0 0x7fd5cee05151 in __interceptor_calloc (/usr/local/fbcode/gcc-5-glibc-2.23/lib/libasan.so.2+0x9a151)
      facebook#1 0x120ea19 in my_malloc /home/tianx/mysql/5.6/mysys/my_malloc.c:38
      facebook#2 0x1891606 in add_pfs_instr_to_array(char const*, char const*) /home/tianx/mysql/5.6/storage/perfschema/pfs_server.cc:251
      facebook#3 0x76bd26 in mysqld_get_one_option /home/tianx/mysql/5.6/sql/mysqld.cc:11033
      facebook#4 0x1242157 in my_handle_options /home/tianx/mysql/5.6/mysys_ssl/my_getopt.cc:659
      facebook#5 0x77d88e in handle_early_options(char) /home/tianx/mysql/5.6/sql/mysqld.cc:8750
      facebook#6 0x78d003 in mysqld_main(int, char**) /home/tianx/mysql/5.6/sql/mysqld.cc:6936
      facebook#7 0x7fd5cc942857 in __libc_start_main (/usr/local/fbcode/gcc-5-glibc-2.23/lib/libc.so.6+0x20857)
      facebook#8 0x764398 in _start (/data/users/tianx/mysql/5.6/_build-5.6-ASan-PerfSchema/sql/mysqld+0x764398)

  SUMMARY: AddressSanitizer: 21 byte(s) leaked in 1 allocation(s).

Test Plan:
mtr and the following test:
  mysqltest.sh --testset=ParallelBig --perfschema --asan --workers=16 auth_sec.secure_file_priv_error

Reviewers: gunnarku

Reviewed By: gunnarku

Subscribers: webscalesql-eng@fb.com

Differential Revision: https://phabricator.intern.facebook.com/D5210977

Tasks: 17217920

Signature: t1:5210977:1497296884:606f6587bfe1595abd7188c1a27f57805b11ee96
  • Loading branch information
tianx committed Jun 12, 2017
1 parent 00cf9e3 commit 54e7744
Showing 1 changed file with 10 additions and 0 deletions.
10 changes: 10 additions & 0 deletions storage/perfschema/pfs_server.cc
Original file line number Diff line number Diff line change
Expand Up @@ -229,7 +229,17 @@ 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))
{
/* Free memory that is allocated for each element */
for (uint i= 0; i < pfs_instr_config_array.elements; i++)
{
PFS_instr_config* e;
get_dynamic(&pfs_instr_config_array, (uchar*)&e, i);
my_free(e);
}
/* Now deallocate the dynamic array */
delete_dynamic(&pfs_instr_config_array);
}
}

/**
Expand Down

0 comments on commit 54e7744

Please sign in to comment.