Bug #71849 memory leak when subquery using order by(make_reverse) and best_key used
Submitted: 26 Feb 2014 21:41 Modified: 4 Apr 2014 12:51
Reporter: xiaobin lin (OCA) Email Updates:
Status: Won't fix Impact on me:
None 
Category:MySQL Server: Optimizer Severity:S3 (Non-critical)
Version:5.5 OS:Any
Assigned to: CPU Architecture:Any
Tags: best_key, make_reverse, memory leak, subquery

[26 Feb 2014 21:41] xiaobin lin
Description:
If subquery calls make_reverse, the new_quick will be alloced.
Then there are cases case select->quick= 0; without deleting it first. 
Leading memory leak.

How to repeat:
As the test case in the patch file.
The test case is for version 5.5 only, but it does not mean the bug do not exist in 5.6.

./mtr memory_leak.test --valgrind

Suggested fix:
As attachment
[26 Feb 2014 21:43] xiaobin lin
the test case here can reproduce the bug in 5.5 only.

(*) I confirm the code being submitted is offered under the terms of the OCA, and that I am authorized to contribute it.

Contribution: 5.5memory_leak.diff (application/octet-stream, text), 19.85 KiB.

[26 Feb 2014 22:20] MySQL Verification Team
Thanks for the report!

20 bytes in 5 blocks are indirectly lost in loss record 1 of 5
at: malloc (vg_replace_malloc.c:291)
by: my_malloc (in ./mysql-5.5.37-linux-x86_64/bin/mysqld)
by: QUICK_RANGE_SELECT::QUICK_RANGE_SELECT (in ./mysql-5.5.37-linux-x86_64/bin/mysqld)
by: TRP_RANGE::make_quick (in ./mysql-5.5.37-linux-x86_64/bin/mysqld)
by: SQL_SELECT::test_quick_select (in ./mysql-5.5.37-linux-x86_64/bin/mysqld)
by: test_if_skip_sort_order (in ./mysql-5.5.37-linux-x86_64/bin/mysqld)
by: create_sort_index (in ./mysql-5.5.37-linux-x86_64/bin/mysqld)
by: JOIN::exec() (in ./mysql-5.5.37-linux-x86_64/bin/mysqld)
by: subselect_single_select_engine::exec() [clone .part.94] (in ./mysql-5.5.37-linux-x86_64/bin/mysqld)
by: Item_subselect::exec() (in ./mysql-5.5.37-linux-x86_64/bin/mysqld)
by: Item_singlerow_subselect::val_str (in ./mysql-5.5.37-linux-x86_64/bin/mysqld)
by: get_datetime_value (in ./mysql-5.5.37-linux-x86_64/bin/mysqld)
by: Arg_comparator::compare_datetime() (in ./mysql-5.5.37-linux-x86_64/bin/mysqld)
by: Item_func_eq::val_int() (in ./mysql-5.5.37-linux-x86_64/bin/mysqld)
by: evaluate_join_record(JOIN*, st_join_table*, int) (in ./mysql-5.5.37-linux-x86_64/bin/mysqld)
by: sub_select (in ./mysql-5.5.37-linux-x86_64/bin/mysqld)
by: do_select (in ./mysql-5.5.37-linux-x86_64/bin/mysqld)
by: JOIN::exec() (in ./mysql-5.5.37-linux-x86_64/bin/mysqld)
by: mysql_select (in ./mysql-5.5.37-linux-x86_64/bin/mysqld)
by: handle_select (in ./mysql-5.5.37-linux-x86_64/bin/mysqld)
by: execute_sqlcom_select (in ./mysql-5.5.37-linux-x86_64/bin/mysqld)
by: mysql_execute_command (in ./mysql-5.5.37-linux-x86_64/bin/mysqld)
by: mysql_parse (in ./mysql-5.5.37-linux-x86_64/bin/mysqld)
by: dispatch_command (in ./mysql-5.5.37-linux-x86_64/bin/mysqld)
by: do_handle_one_connection(THD*) (in ./mysql-5.5.37-linux-x86_64/bin/mysqld)
by: handle_one_connection (in ./mysql-5.5.37-linux-x86_64/bin/mysqld)
by: start_thread (pthread_create.c:309)
by: clone (clone.S:115)

similar internal bug:
Bug 16102780 - MEMORY LEAKS FROM QUICK_RANGE_SELECT
[4 Apr 2014 12:51] Jørgen Løland
Hi.

Thank you for the patch. This bug was fixed in MySQL 5.6 in September 2011 by this revision:

revid:guilhem.bichot@oracle.com-20110930122004-3jw70shhcgywb4qz

There are no plans to backport the fix. We suggest an upgrade to MySQL 5.6