Monday, October 26, 2015

MySQL 5.7 Versus the Address Sanitizer

MySQL 5.7 supports the Address Sanitizer, which checks for several memory related software errors including memory leaks.  It is really nice to see support for the Address Sanitizer built into MySQL.  Unfortunately, when running the mysql tests included in MySQL 5.7.9, the Address Sanitizer reports several memory leaks, which causes some of  the tests to fail.  Here are some of the memory leaks in the MySQL 5.7.9 software found by the Address Sanitizer.

Memory leaks in 'mysqlbinlog'

Several of the 'mysqlbinlog' tests fail due to memory leaks in the 'mysqlbinlog' client program.  Here are the details from the 'main.mysqlbinlog' test.  It appears the binlog event objects are not always deleted after being created by the 'dump_remote_log_entries' function.

See MySQL bugs 78966 and 78223 for status.

Memory leaks in 'mysqlpump'

All of the 'mysqlpump' tests fail due to memory leaks in the 'mysqlpump' client program.  Here are the details from the 'main.mysqlpump_basic' test.  The first memory leak occurs in the 'quote_name' function, which gets a object pointer and then just dicards it.  Other memory leaks are caused by a similar disregard for object management.  Unfortunately, C++ requires the programmer to manage memory.  Use of the Address Sanitizer when developing and testing new C++ software like 'mysqlpump' will quickly identify the memory leaks.

See MySQL bugs 78965 and 78224 for status.

Memory leaks in InnoDB

Several InnoDB tests fail due to memory leaks in the InnoDB storage engine when running the mysqld server.  Here are the details from the 'log_file_name' test.  The memory leaks occur because InnoDB calls the 'exit' system call from its initialization function rather than passing an error back to the mysqld server code.   Since InnoDB can abruptly terminate mysqld, this sets a precedent that allows any storage engine or plugin to do the same when it encounters a problem.  IMO, a plugin should not be allowed to terminate the mysql server especially for a 'simple' case of an error during plugin initialization.


Since it is really easy to leak memory in C++ programs, C++ developers should use a memory verification tool like valgrind's memcheck or the Address Sanitizer to find memory leaks.  Since support for the Address Sanitizer is built into MySQL, it should be used when hacking on MySQL software.  Furthermore, since the executing cost of the Address Sanitizer is reasonable (IMO), it could be used in an automated MySQL test system.

I have only run the 'main' and 'innodb' mysql tests suites with the Address Sanitizer.  There are plenty of additional tests suites that are part of the MySQL software that should be run with the Address Sanitizer.


MySQL 5.7.9
Address Sanitizer built into Clang 3.8
Ubuntu 14.04


  1. Created MySQL bug to track the InnoDB test failures due to memory leaks due to a premature mysqld exit.

  2. Updated to MySQL 5.7.11, Ubuntu 15.10, and clang 3.9.0.

  3. This comment has been removed by a blog administrator.