Bug #46164 memory leak in mysqltest after parse error with --debug
Submitted: 14 Jul 2009 9:15 Modified: 19 Dec 2009 0:09
Reporter: Sven Sandberg Email Updates:
Status: Closed Impact on me:
None 
Category:Tools: MTR / mysql-test-run Severity:S3 (Non-critical)
Version:5.1 OS:Linux
Assigned to: Bjørn Munch CPU Architecture:Any
Tags: memory leak, mysqltest

[14 Jul 2009 9:15] Sven Sandberg
Description:
When running mtr --debug, the following query causes mysqltest to leak memory:

insert into t1 values (1) blah;

How to repeat:
$ cat t/bug.test
insert into t1 values (1) blah;

$ ./mtr --debug bug
Logging: ./mtr  --debug bug
090714 11:14:54 [Note] Plugin 'FEDERATED' is disabled.
090714 11:14:54 [Note] Plugin 'ndbcluster' is disabled.
090714 11:14:54 [Warning] Forcing shutdown of 2 plugins
MySQL Version 5.1.36
Checking supported features...
 - using ndbcluster when necessary, mysqld supports it
 - SSL connections supported
 - binaries are debug compiled
Collecting tests...
vardir: /home/sven/bzr/b39934-mats-slave_row_engine/5.1-bugteam/mysql-test/var
Checking leftover processes...
Removing old var directory...
Creating var directory '/home/sven/bzr/b39934-mats-slave_row_engine/5.1-bugteam/mysql-test/var'...
Installing system database...
Using server port 36940
worker[1] Using MTR_BUILD_THREAD 2, with reserved ports 10020..10029

==============================================================================

TEST                                      RESULT   TIME (ms)
------------------------------------------------------------

main.sven_bug_1                          [ fail ]
        Test ended at 2009-07-14 11:14:57

CURRENT_TEST: main.sven_bug_1
mysqltest: At line 1: query 'insert into t1 values (uuid()) blah' failed: 1064: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'blah' at line 1
Warning: Not freed memory segments: 1
Warning: Memory that was not free'ed (256 bytes):
	   256 bytes at 0x9d43760, allocated at line   39 in 'string.c'

 - saving '/home/sven/bzr/b39934-mats-slave_row_engine/5.1-bugteam/mysql-test/var/log/main.sven_bug_1/' to '/home/sven/bzr/b39934-mats-slave_row_engine/5.1-bugteam/mysql-test/var/log/main.sven_bug_1/'
------------------------------------------------------------
The servers were restarted 0 times
Spent 0.000 of 3 seconds executing testcases

Failed 1/1 tests, 0.00% were successful.

Failing test(s): main.sven_bug_1

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
[18 Aug 2009 13:27] Bugs System
A patch for this bug has been committed. After review, it may
be pushed to the relevant source trees for release in the next
version. You can access the patch from:

  http://lists.mysql.com/commits/80988

2819 Bjorn Munch	2009-08-18
      Bug #46164 memory leak in mysqltest after parse error with --debug
      Moved some dynstr_free() further up
[18 Aug 2009 13:30] Bjørn Munch
Reproduced using valgrind; those strings do accumulate also if the SQL errors are ignored. Fixed (and verified) by moving dynstr_free() a bit further up.
[27 Aug 2009 10:05] Magnus Blåudd
Godd, freeing the allocated memory as soon it's not used anymore in the function.

In general I would say that mysqltest is not written to properly clean up memory properly before _every_ place it can die since that would mostly clutter the cod up even more and it's just going to die anyway so just let the OS handle it. 

But in cases like this when it's kind of a normal exit point it makes sense to fix it, especially since it does not lead to code duplication.

In the long run, the dynamic string C functions could be wrapped in a C++ wrapper and let the destructor take care of it.
[27 Aug 2009 10:35] Bugs System
A patch for this bug has been committed. After review, it may
be pushed to the relevant source trees for release in the next
version. You can access the patch from:

  http://lists.mysql.com/commits/81700

2820 Bjorn Munch	2009-08-27 [merge]
      Bug #46164 memory leak in mysqltest after parse error with --debug
      Moved some dynstr_free() further up
[27 Aug 2009 10:51] Bjørn Munch
Pushed to azalea-mtr (soon to be renamed next-mtr) and 5.1-mtr
[3 Sep 2009 17:11] Bugs System
Pushed into 5.1.40 (revid:bjorn.munch@sun.com-20090903170735-679d64zp580wl39j) (version source revid:bjorn.munch@sun.com-20090903170735-679d64zp580wl39j) (merge vers: 5.1.40) (pib:11)
[4 Sep 2009 0:59] Paul DuBois
Test suite change. No changelog entry needed.

Setting report to NDI pending push into 5.4.x.
[30 Sep 2009 8:16] Bugs System
Pushed into 6.0.14-alpha (revid:alik@sun.com-20090929093622-1mooerbh12e97zux) (version source revid:alik@sun.com-20090922182109-vs5ign07cwht12z6) (merge vers: 6.0.14-alpha) (pib:11)
[30 Sep 2009 8:20] Bugs System
Pushed into 5.4.5-beta (revid:alik@sun.com-20090925094254-tjl9eajkzwzgthoe) (version source revid:alik@sun.com-20090922142453-x275o41whpyezh4q) (merge vers: 5.4.4-beta) (pib:11)
[30 Sep 2009 19:43] Paul DuBois
Test suite change. No changelog entry needed.
[18 Dec 2009 10:38] Bugs System
Pushed into 5.1.41-ndb-7.1.0 (revid:jonas@mysql.com-20091218102229-64tk47xonu3dv6r6) (version source revid:jonas@mysql.com-20091218095730-26gwjidfsdw45dto) (merge vers: 5.1.41-ndb-7.1.0) (pib:15)
[18 Dec 2009 10:53] Bugs System
Pushed into 5.1.41-ndb-6.2.19 (revid:jonas@mysql.com-20091218100224-vtzr0fahhsuhjsmt) (version source revid:jonas@mysql.com-20091217101452-qwzyaig50w74xmye) (merge vers: 5.1.41-ndb-6.2.19) (pib:15)
[18 Dec 2009 11:08] Bugs System
Pushed into 5.1.41-ndb-6.3.31 (revid:jonas@mysql.com-20091218100616-75d9tek96o6ob6k0) (version source revid:jonas@mysql.com-20091217154335-290no45qdins5bwo) (merge vers: 5.1.41-ndb-6.3.31) (pib:15)
[18 Dec 2009 11:22] Bugs System
Pushed into 5.1.41-ndb-7.0.11 (revid:jonas@mysql.com-20091218101303-ga32mrnr15jsa606) (version source revid:jonas@mysql.com-20091218064304-ezreonykd9f4kelk) (merge vers: 5.1.41-ndb-7.0.11) (pib:15)