Bug #56647 Valgrind warnings for memory leak in mysqltest.cc
Submitted: 8 Sep 2010 13:55 Modified: 14 Nov 2010 2:51
Reporter: Sven Sandberg Email Updates:
Status: Closed Impact on me:
None 
Category:Tools: MTR / mysql-test-run Severity:S3 (Non-critical)
Version:trunk OS:Any
Assigned to: Bjørn Munch CPU Architecture:Any
Tags: memory leak, mtr, mysqltest, valgrind

[8 Sep 2010 13:55] Sven Sandberg
Description:
This is one of several Valgrind warnings for trunk-bugfixing in pb2 at https://central.sun.net/http://pb2.norway.sun.com/?action=archive_download&archive_id=2239... :

==13347== 256 bytes in 1 blocks are still reachable in loss record 4 of 6
==13347==    at 0x4A05809: malloc (vg_replace_malloc.c:149)
==13347==    by 0x44FCA0: my_malloc (my_malloc.c:38)
==13347==    by 0x452E07: init_dynamic_string (string.c:39)
==13347==    by 0x4195A1: run_query(st_connection*, st_command*, int) (mysqltest.cc:7352)
==13347==    by 0x41B2F8: main (mysqltest.cc:8200)

How to repeat:
Read the log.

Suggested fix:
I think this should fix it:

=== modified file 'client/mysqltest.cc'
--- client/mysqltest.cc	2010-08-27 12:17:32 +0000
+++ client/mysqltest.cc	2010-09-06 15:35:36 +0000
@@ -7349,11 +7349,11 @@
                            (flags & QUERY_REAP_FLAG));
   DBUG_ENTER("run_query");
 
-  init_dynamic_string(&ds_warnings, NULL, 0, 256);
-
   if (cn->pending && (flags & QUERY_SEND_FLAG))
     die ("Cannot run query on connection between send and reap");
 
+  init_dynamic_string(&ds_warnings, NULL, 0, 256);
+
   /*
     Evaluate query if this is an eval command
   */
[10 Sep 2010 11:11] 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/117995

2929 Bjorn Munch	2010-09-10
      Bug #56647 Valgrind warnings for memory leak in mysqltest.cc
      Moved an init_dynamic_string() from before to after potential die()
[14 Sep 2010 9:40] Magnus Blåudd
In general I think it's OK to leave some memory behind when mysqltest exits with an error message like this, the OS will free it for us.

Of course the "normal paths" should be leak free.
[14 Sep 2010 12:54] Bjørn Munch
Pushed to -mtr branches
[7 Oct 2010 22:58] Paul DuBois
Changes to test suite. No changelog entry needed.
[1 Nov 2010 19:01] Bugs System
Pushed into mysql-5.1 5.1.53 (revid:build@mysql.com-20101101184443-o2olipi8vkaxzsqk) (version source revid:build@mysql.com-20101101184443-o2olipi8vkaxzsqk) (merge vers: 5.1.53) (pib:21)
[9 Nov 2010 19:45] Bugs System
Pushed into mysql-5.5 5.5.7-rc (revid:sunanda.menon@sun.com-20101109182959-otkxq8vo2dcd13la) (version source revid:sunanda.menon@sun.com-20101109182959-otkxq8vo2dcd13la) (merge vers: 5.5.7-rc) (pib:21)
[13 Nov 2010 16:15] Bugs System
Pushed into mysql-trunk 5.6.99-m5 (revid:alexander.nozdrin@oracle.com-20101113155825-czmva9kg4n31anmu) (version source revid:alexander.nozdrin@oracle.com-20101113152450-2zzcm50e7i4j35v7) (merge vers: 5.6.1-m4) (pib:21)
[13 Nov 2010 16:33] Bugs System
Pushed into mysql-next-mr (revid:alexander.nozdrin@oracle.com-20101113160336-atmtmfb3mzm4pz4i) (version source revid:vasil.dimov@oracle.com-20100629074804-359l9m9gniauxr94) (pib:21)