Bug #59153 mysqltest produces a valgrind warning when the running test fails
Submitted: 24 Dec 2010 9:06 Modified: 29 Jan 2011 23:05
Reporter: Alexander Nozdrin Email Updates:
Status: Closed Impact on me:
None 
Category:MySQL Server: Command-line Clients Severity:S3 (Non-critical)
Version:5.6.1 OS:Any
Assigned to: Bjørn Munch CPU Architecture:Any
Tags: pb2, test failure

[24 Dec 2010 9:06] Alexander Nozdrin
Description:
mysqltest: At line 33: query 'ALTER TABLE tp EXCHANGE PARTITION p0 WITH TABLE t_10' succeeded - should have failed with errno 1710...

The result from queries just before the failure was:
use test;
==2598== 
==2598== HEAP SUMMARY:
==2598==     in use at exit: 1,816 bytes in 6 blocks
==2598==   total heap usage: 1,091 allocs, 1,085 frees, 545,484 bytes allocated
==2598== 
==2598== 256 bytes in 1 blocks are still reachable in loss record 4 of 6
==2598==    at 0x4C20E1C: malloc (vg_replace_malloc.c:195)
==2598==    by 0x43A0C1: my_malloc (my_malloc.c:38)
==2598==    by 0x4313F3: init_dynamic_string (string.c:39)
==2598==    by 0x414989: run_query(st_connection*, st_command*, int) (mysqltest.cc:7689)
==2598==    by 0x41681B: main (mysqltest.cc:8634)

How to repeat:
Tree: http://pb2.norway.sun.com/?template=show_pushes&branch=mysql-5.6.1-m5-release

Log: http://pb2.norway.sun.com/?action=archive_download&archive_id=2710734&pretty=please

See also Bug#59148,
[4 Jan 2011 5:30] Anitha Gopi
Appears to be an MTR problem.
[4 Jan 2011 13:08] 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/127872

3135 Bjorn Munch	2011-01-04
      Bug #59153 mysqltest produces a valgrind warning when the running test fails
      Local variable ds_warnings in run_query not cleared.
      But when we call die() we don't have access to it.
      Set global var. to point to it when allocated.
[11 Jan 2011 9:04] Magnus Blåudd
I would actually say "Won't fix" since mysqltest is not designed to free all memory when calling "die".

If you really want to fix the problem, write Dynamic string class that automatically frees the memory allocated when it goes out of scope.

class DynamicString {
  DYNAMIC_STRING m_str;
public:
  DynamicString(...) {
    init_dynamic_string(m_str...)
  }
  ~DynamicString() {
    dynstr_free(m_str);
  }
  bool append(const char* str, len) {
    return dynstr_append(m_str, str, len);
  }
  and so on...
}

then use like

void run_query(..)
{
  DynamicString ds_warnings(NULL, 0, 256);

  run_query_normal(ds_warnings);

}
[11 Jan 2011 9:29] Bjørn Munch
Ah yes, I forget this is actually C++ now. :-) Of course this is the proper way, I'll probably make a simple one just to cover this case, then may add a general solution later.
[11 Jan 2011 10:05] Bjørn Munch
No wait. When we die() and do exit from within run_query, the variable declared there will NOT go out of scope. So no destructor will automatically be called.
[11 Jan 2011 14:24] 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/128434

3140 Bjorn Munch	2011-01-11
      Bug #59153 mysqltest produces a valgrind warning when the running test fails
      Local variable ds_warnings in run_query not cleared.
      But when we call die() we don't have access to it.
      Set global var. to point to it when allocated.
[12 Jan 2011 10:29] Bjørn Munch
Pushed to 5.5-mtr and trunk-mtr
[12 Jan 2011 23:24] Bugs System
Pushed into mysql-trunk 5.6.2 (revid:bjorn.munch@oracle.com-20110112231827-w6nuz7qcr3f2zylq) (version source revid:bjorn.munch@oracle.com-20110112225756-g2nv4mukrmvnl3uz) (merge vers: 5.6.2) (pib:24)
[12 Jan 2011 23:26] Bugs System
Pushed into mysql-5.5 5.5.9 (revid:bjorn.munch@oracle.com-20110112225418-3zw6jvo3jywfqsva) (version source revid:bjorn.munch@oracle.com-20110112223239-fep31owswretsv6w) (merge vers: 5.5.9) (pib:24)
[13 Jan 2011 9:23] Bjørn Munch
The push message(s) are premature; the bug goes into the version(s) *after* the one mentioned.
[14 Jan 2011 17:29] Paul DuBois
Changes to test suite. No changelog entry needed.