Bug #42695 memory leak when setting backupdir
Submitted: 9 Feb 2009 13:56 Modified: 26 Mar 2009 23:52
Reporter: Shane Bester (Platinum Quality Contributor) Email Updates:
Status: Closed Impact on me:
None 
Category:MySQL Server: Backup Severity:S3 (Non-critical)
Version:6.0.9, 6.0.10 OS:Any
Assigned to: Chuck Bell CPU Architecture:Any
Tags: memory leak

[9 Feb 2009 13: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 2009 14:17] MySQL Verification Team
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 2009 10: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 2009 10:17] Sveta Smirnova
Both memory leak and crash without stack trace verified as described using test case provided in the above comment.
[11 Feb 2009 16:53] Chuck Bell
May be related to BUG#42685 -- either similar patch or related bug.
[20 Feb 2009 13:37] Chuck Bell
Chuck steals a bug from Rafal... :P
[20 Feb 2009 15: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 2009 19: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 2009 10:40] Ingo Strüwing
Approved. Please see email.
[26 Feb 2009 15:21] Jørgen Løland
Good to push.
[26 Feb 2009 22: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 2009 12: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)
[26 Mar 2009 23:52] Paul DuBois
Noted in 6.0.11 changelog.

Assigning a value to the backupdir system variable resulted in a
memory leak.
[11 Jan 2010 17:02] 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/96533

3051 Ingo Struewing	2010-01-11
      WL#5101 - MySQL Backup back port
      Merged revid:charles.bell@sun.com-20090226221909-3j941x1qlvsd51w2
        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.
      
      original changeset: 2599.123.12
     @ mysql-test/suite/backup/r/backup_logs.result
        WL#5101 - MySQL Backup back port
        Updated test result for change in version string length.
     @ sql/set_var.cc
        WL#5101 - MySQL Backup back port
            Added code to ensure users do not attempt to assign a path longer
            than FN_REFLEN.