Bug #47688 query memory is leaked after mysql client quits
Submitted: 28 Sep 2009 20:18 Modified: 29 Sep 2009 3:43
Reporter: Shane Bester (Platinum Quality Contributor) Email Updates:
Status: Verified Impact on me:
None 
Category:MySQL Server: Command-line Clients Severity:S3 (Non-critical)
Version:5.0.85, 5.1.39, 5.1.40-bzr OS:Any
Assigned to: CPU Architecture:Any
Tags: Leak, valgrind

[28 Sep 2009 20:18] Shane Bester
Description:
last query memory is leaked after mysql client quits.  the leak is harmless, since the client quits anyway, but still needs to be fixed since valgrind errors are not very professional to leave behind. 

from 5.1.39 client:

==20210== 5 bytes in 1 blocks are definitely lost in loss record 10 of 36
==20210==    at 0x4005993: malloc (vg_replace_malloc.c:195)
==20210==    by 0x809F230: xmalloc (xmalloc.c:60)
==20210==    by 0x8088F82: readline_internal_teardown (readline.c:410)
==20210==    by 0x8089B4E: readline (readline.c:560)
==20210==    by 0x80825EF: read_and_execute(bool) (mysql.cc:1901)
==20210==    by 0x80843DA: main (mysql.cc:1216)

How to repeat:
valgrind --tool=memcheck --track-origins=yes --leak-check=full --db-attach=no -v --show-reachable=no ./bin/mysql -uroot

Then type 'quit'.

The length of the last query is leaked.

Suggested fix:
free the memory before exiting
[29 Sep 2009 3:43] Valeriy Kravchuk
Verified just as described with recent 5.1.40 from bzr on Mac OS X (more leaks reported actually, not only this).