Bug #71283 mysqlbinlog memory leak when --rewrite-db option is used

Submitted: 3 Jan 2014 5:02 Modified: 12 Feb 2014 21:59
Reporter: Vlad Lesin Email Updates:
Status: Closed Impact on me:
None 
Category:MySQL Server: Command-line Clients Severity:S3 (Non-critical)
Version:5.7.3 OS:Any
Assigned to: CPU Architecture:Any
Tags: mysqlbinlog rewrite-db

[3 Jan 2014 5:02] Vlad Lesin
Description:
The function get_binlog_rewrite_db() extracts the to_db name from the list of the from_db and to_db pairs into rewrite_to_db global variable. rewrite_to_db is a pointer which points to the memory where db_to name is stored as a null-terminated string.  The memory for storing to_db string is allocated in get_binlog_rewrite_db() function every time when the element with corresponding from_db is found in binlog_rewrite_db container. But there is no place in the code where this memory is deallocated.

How to repeat:
The bellow actions was done on the code from lp:mysql-server repository revision number 6864 tag mysql-5.7.3 with -DCMAKE_BUILD_TYPE=Debug cmake option.

The bug can be repeated by launching mysqlbinlog under valgrind with --replace-db="db1->db2" option with binlog file generated by "mysql-test/suite/binlog/t/binlog_mysqlbinlog_rewrite_db.test" test. To make things easier I will attach this binlog file.

The following is the example of how bug can be repeated:
valgrind --leak-check=full ../client/mysqlbinlog --rewrite-db='db1->db2' /tmp/1/master-bin.000001
...
==2749== 20 bytes in 1 blocks are possibly lost in loss record 1 of 5
==2749==    at 0x4C2CD7B: malloc (in /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so)
==2749==    by 0x4834A8: my_raw_malloc (my_malloc.c:157)
==2749==    by 0x483156: my_malloc (my_malloc.c:48)
==2749==    by 0x416D6D: get_binlog_rewrite_db(char const*) (log_event.cc:194)
==2749==    by 0x416E4B: rewrite_buffer(char**, int, Format_description_log_event const*) (log_event.cc:239)
==2749==    by 0x417A38: Log_event::read_log_event(st_io_cache*, Format_description_log_event const*, char) (log_event.cc:1546)
==2749==    by 0x40F10E: dump_local_log_entries(st_print_event_info*, char const*) (mysqlbinlog.cc:2709)
==2749==    by 0x40D368: dump_log_entries(char const*) (mysqlbinlog.cc:1954)
==2749==    by 0x40F90E: main (mysqlbinlog.cc:2981)

As well there are another memory leaks in valgrind report.
[3 Jan 2014 5:03] Vlad Lesin
binlog file to repeate the bug

Attachment: master-bin.000001 (application/octet-stream, text), 1.09 KiB.

[3 Jan 2014 9:47] MySQL Verification Team
Hello Vlad,

Thank you for the bug report.
Verified as described.

Thanks,
Umesh
[12 Feb 2014 21:59] Paul DuBois
Noted in 5.7.4 changelog.

mysqlbinlog leaked memory in relation to --rewrite-db processing.

Portions of this website are copyright © 2001, 2002 The PHP Group

Page generated in 0.040 sec. using MySQL 8.4.7-u6-cloud

Timestamp references displayed by the system are UTC.
Content reproduced on this site is the property of the respective copyright holders.
It is not reviewed in advance by Oracle and does not necessarily represent the opinion of Oracle or any other party.