Bug #80089 Memory leak from open files limit
Submitted: 21 Jan 2016 1:58 Modified: 9 May 2016 14:52
Reporter: Manuel Ung Email Updates:
Status: Closed Impact on me:
None 
Category:MySQL Server: Options Severity:S3 (Non-critical)
Version:5.6, 5.6.28 OS:Linux
Assigned to: CPU Architecture:Any

[21 Jan 2016 1:58] Manuel Ung
Description:
When calling adjust_open_files_limit, we use Buffered_logs to output messages. 

However, the contents of buffered_logs are never free'd when perfschema is off.

How to repeat:
Build with -WITH_PERFSCHEMA_STORAGE_ENGINE=0

Make sure that ulimit -n is lower than 65535.

Run ./mtr --valgrind parts.partition_max_parts_hash_myisam

Observe memory leak errors from Valgrind.

Suggested fix:
Either:

Don't use buffered_logs for non-perfschema builds (since they don't appear to be printed out anyway), or

Always free buffered_logs
[21 Jan 2016 7:26] Umesh Shastry
Hello Manuel,

Thank you for the report.
Observed this with 5.6.28 source build.

Thanks,
Umesh
[21 Jan 2016 7:30] Umesh Shastry
-- 5.6.28

[ushastry@cluster-repo mysql-test]# ./mtr  --valgrind parts.partition_max_parts_hash_myisam
Logging: ./mtr  --valgrind parts.partition_max_parts_hash_myisam
.
.
HEAP SUMMARY:
    in use at exit: 1,072 bytes in 2 blocks
  total heap usage: 339,925 allocs, 339,923 frees, 8,738,614,941 bytes allocated

80 bytes in 1 blocks are still reachable in loss record 1 of 2
   at 0x4C27A2E: malloc (vg_replace_malloc.c:270)
   by 0x89D1B1: my_malloc (my_malloc.c:38)
   by 0x6EADB1: String::copy(char const*, unsigned int, charset_info_st const*) (sql_string.cc:46)
   by 0x55BE47: Buffered_logs::buffer(loglevel, char const*) [clone .clone.6] (mysqld.cc:1025)
   by 0x55C04C: adjust_open_files_limit(unsigned long*) (mysqld.cc:6903)
   by 0x5601E1: mysqld_main(int, char**) (mysqld.cc:6974)
   by 0x5E4DD5C: (below main) (in /lib64/libc-2.12.so)

992 bytes in 1 blocks are still reachable in loss record 2 of 2
   at 0x4C27A2E: malloc (vg_replace_malloc.c:270)
   by 0x89D1B1: my_malloc (my_malloc.c:38)
   by 0x89954A: alloc_root (my_alloc.c:224)
   by 0x55BDF8: Buffered_logs::buffer(loglevel, char const*) [clone .clone.6] (sql_alloc.h:40)
   by 0x55C04C: adjust_open_files_limit(unsigned long*) (mysqld.cc:6903)
   by 0x5601E1: mysqld_main(int, char**) (mysqld.cc:6974)
   by 0x5E4DD5C: (below main) (in /lib64/libc-2.12.so)

LEAK SUMMARY:
   definitely lost: 0 bytes in 0 blocks
   indirectly lost: 0 bytes in 0 blocks
     possibly lost: 0 bytes in 0 blocks
   still reachable: 1,072 bytes in 2 blocks
        suppressed: 0 bytes in 0 blocks

For counts of detected and suppressed errors, rerun with: -v
ERROR SUMMARY: 0 errors from 0 contexts (suppressed: 6 from 6)

valgrind_report                          [ fail ]
        Test ended at 2016-01-23 19:39:28

Valgrind reported failures at shutdown, see above

--------------------------------------------------------------------------
The servers were restarted 0 times
Spent 112.340 of 129 seconds executing testcases

Completed: Failed 1/2 tests, 50.00% were successful.

Failing test(s): valgrind_report

The log files in var/log may give you some hint of what went wrong.

If you want to report this error, please read first the documentation
at http://dev.mysql.com/doc/mysql/en/mysql-test-suite.html

mysql-test-run: *** ERROR: there were failing test cases
[9 May 2016 14:52] Paul Dubois
Posted by developer:
 
Noted in 5.6.31, 5.7.13 changelogs.

For a server compiled with -DWITH_PERFSCHEMA_STORAGE_ENGINE=0, a 
memory leak could occur for buffered log messages used during server
startup.