Bug #37363 Mysql test has memory leak when query fails
Submitted: 12 Jun 2008 12:22 Modified: 30 Jul 2008 16:07
Reporter: Jørgen Løland Email Updates:
Status: Can't repeat Impact on me:
None 
Category:Tests Severity:S3 (Non-critical)
Version:6.0.5 OS:Any
Assigned to: CPU Architecture:Any

[12 Jun 2008 12:22] Jørgen Løland
Description:
DYNAMIC_STRING ds_warnings in mysqltest.c#run_query is not freed if a query fails. ds_warnings is normally freed at the end of the run_query method, but when a query fail, the program exits without getting to this code:

#0  cleanup_and_exit (exit_code=1) at mysqltest.c:979
#1  0x0804e590 in die (fmt=0x806ec04 "query '%s' failed: %d: %s")
    at mysqltest.c:1049
#2  0x08058698 in handle_error (command=0x813fb00, err_errno=1683, 
    err_error=0x80f4f7f "", err_sqlstate=0x80f517f "00000", ds=0x80f4ef8)
    at mysqltest.c:6019
#3  0x08058317 in run_query_normal (cn=0x80f4f20, command=0x813fb00, flags=3, 
    query=0x812b7a8 "BACKUP DATABASE d2 TO '3'", query_len=25, ds=0x80f4ef8, 
    ds_warnings=0xbf86402c) at mysqltest.c:5886
#4  0x0805967f in run_query (cn=0x80f4f20, command=0x813fb00, flags=3)
    at mysqltest.c:6545
#5  0x0805a9fb in main (argc=20, argv=0xbf864414) at mysqltest.c:7061

How to repeat:
I reproduce this consistently in my local repository, but the server code I get this in is not in a pushable condition. Not sure how to reproduce this in other cases.

Suggested fix:
Not sure
[11 Jul 2008 21:01] Sveta Smirnova
Thank you for the report.

I tested with debugger with current 6.0 bzr tree:

1. Create file bug37363.test:
let $i=5;
while ($i)
{
--error 1064
  select 1+;
}
2. Run ./mysql-test-run.pl bug37363
3. In other window:

gdb  ~/bzr/mysql-6.0/client/.libs/mysqltest  PID
...
(gdb) b 6578 (string where dynstr_free(&ds_warnings); is calling)
(gdb) c
Continuing.

Breakpoint 1, run_query (cn=0xaaf10, command=0x1818418, flags=3) at mysqltest.c:6578
6578      dynstr_free(&ds_warnings);
(gdb) p command->query
$5 = 0x1101bd8 "select 1+"

It shows ds_warnings frees even if query fails. Please correct me if my test is wrong.
[30 Jul 2008 8:38] Jørgen Løland
I'm no longer able to reproduce the memory-not-freed warning.
[30 Jul 2008 16:07] Sveta Smirnova
Thank you for the feedback.

Set to "Can't repeat", because last comment.