Bug #42695 memory leak when setting backupdir
Submitted: 9 Feb 14:56 Modified: 27 Mar 0:52
Reporter: Shane Bester
Status: Closed
Category:Server: Backup Severity:S3 (Non-critical)
Version:6.0.9, 6.0.10 OS:Any
Assigned to: Chuck Bell Target Version:6.0-beta
Tags: memory leak
Triage: Triaged: D1 (Critical)

[9 Feb 14:56] Shane Bester
Description:
offspring from bug #42685

Setting backupdir global variable leaks memory

How to repeat:
set global max_allowed_packet=1024*1024*100;
\r
set global backupdir=repeat('a',99*1024*1024);
set global backupdir=repeat('a',99*1024*1024);
set global backupdir=repeat('a',99*1024*1024);
set global backupdir=repeat('a',99*1024*1024);
[9 Feb 15:17] Shane Bester
the server crashes without stack trace when the memory is exhausted. this is another bug.
server should return an out of memory error message instead of crashing.
[11 Feb 11:10] Sveta Smirnova
Thank you for the report.

Memory leak verified using following test:

set global max_allowed_packet=1024*1024*100;

connect (addconroot, localhost, root,,);
connection addconroot;

--disable_query_log
--let $i=1000
while ($i)
{
set global backupdir=repeat('a',99*1024*1024);
--dec $i
}
--enable_query_log

select 1;

(Run test using MTR and observe memory usage with top)
[11 Feb 11:17] Sveta Smirnova
Both memory leak and crash without stack trace verified as described using test case
provided in the above comment.
[11 Feb 17:53] Chuck Bell
May be related to BUG#42685 -- either similar patch or related bug.
[20 Feb 14:37] Chuck Bell
Chuck steals a bug from Rafal... :P
[20 Feb 16:17] Chuck Bell
Working theory: The backupdir is implemented in the same way as the other directory
variables except that the backupdir can be changed at runtime. Thus, the others do not
delete any allocated memory. The patch should change the backupdir code to delete used
memory when the variable is updated. Either the old value or the value specified in the
sys_var_update_backupdir() call in set_var.cc.
[25 Feb 20:59] 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/67606

2780 Chuck Bell	2009-02-25
      BUG#42695 : memory leak when setting backupdir
      BUG#42685 : valgrind errors setting backup_progress_log_file
      
      The patch for these bugs both use the new error message and in many
      ways similar so thus the combined patch.
      
      This patch adds code to detect when users attempt to set a path 
      longer than FN_REFLEN. 
      
      For BUG#42695, the patch also frees memory used when a successful 
      update to the backupdir variable is completed.
      modified:
        mysql-test/suite/backup/r/backup_backupdir.result
        mysql-test/suite/backup/r/backup_logs.result
        mysql-test/suite/backup/t/backup_backupdir.test
        mysql-test/suite/backup/t/backup_logs.test
        sql/set_var.cc
        sql/share/errmsg.txt
[26 Feb 11:40] Ingo Strüwing
Approved. Please see email.
[26 Feb 16:21] Jorgen Loland
Good to push.
[26 Feb 23:19] 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/67749

2788 Chuck Bell	2009-02-26
      BUG#42695 : memory leak when setting backupdir
      BUG#42685 : valgrind errors setting backup_progress_log_file
      
      This patch adds code to detect when users attempt to set a path 
      longer than FN_REFLEN. 
      
      For BUG#42695, the patch also frees memory used when a successful 
      update to the backupdir variable is completed.
      modified:
        mysql-test/suite/backup/r/backup_backupdir.result
        mysql-test/suite/backup/r/backup_logs.result
        mysql-test/suite/backup/t/backup_backupdir.test
        mysql-test/suite/backup/t/backup_logs.test
        sql/set_var.cc
        sql/share/errmsg.txt
[26 Mar 13:34] Bugs System
Pushed into 6.0.11-alpha (revid:alik@sun.com-20090326121822-pt84kzxxayzho4mn) (version
source revid:rafal.somla@sun.com-20090302164601-znhm4tadplfi2iqu) (merge vers:
6.0.11-alpha) (pib:6)
[27 Mar 0:52] Paul DuBois
Noted in 6.0.11 changelog.

Assigning a value to the backupdir system variable resulted in a
memory leak.