Bug #54764 memory allocated in os_aio_array_create is not freed at shutdown
Submitted: 24 Jun 2010 8:19 Modified: 14 Sep 2010 18:03
Reporter: Shane Bester (Platinum Quality Contributor) Email Updates:
Status: Closed Impact on me:
None 
Category:MySQL Server: InnoDB storage engine Severity:S3 (Non-critical)
Version:5.5.5, innodb 1.1.1 OS:Any
Assigned to: Jimmy Yang CPU Architecture:Any

[24 Jun 2010 8:19] Shane Bester
Description:
20,480 bytes in 1 blocks are definitely lost in loss record 16 of 16
at: malloc (vg_replace_malloc.c:195)
by: ut_malloc_low (ut0mem.c:106)
by: ut_malloc (ut0mem.c:244)
by: os_aio_array_create (os0file.c:3261)
by: os_aio_init (os0file.c:3366)
by: innobase_start_or_create_for_mysql (srv0start.c:1329)
by: innobase_init(void*) (ha_innodb.cc:2421)
by: ha_initialize_handlerton(st_plugin_int*) (handler.cc:476)
by: plugin_initialize(st_plugin_int*) (sql_plugin.cc:1052)
by: plugin_init(int*, char**, int) (sql_plugin.cc:1338)
by: init_server_components() (mysqld.cc:4163)
by: mysqld_main(int, char**) (mysqld.cc:4764)
by: main (main.cc:24)

LEAK SUMMARY:
 definitely lost: 30,040 bytes in 10 blocks
 indirectly lost: 0 bytes in 0 blocks
   possibly lost: 272 bytes in 1 blocks
 still reachable: 1,552 bytes in 5 blocks
      suppressed: 0 bytes in 0 blocks

my system:
valgrind-3.5.0
gcc (GCC) 4.1.2 20061115 (prerelease) (SUSE Linux)
bzr+ssh://XXX@bk-internal.mysql.com/bzrroot/server/mysql-trunk/
Now on revision 3072
Built using: 

How to repeat:
valgrind --tool=memcheck --track-origins=yes --leak-check=full -v --show-reachable=y
es --num-callers=50 ./bin/mysqld --no-defaults --skip-grant-tables --skip-name-resolve --basedir=. --datadir=./data

mysqladmin -uroot -h127.0.0.1 shutdown

Suggested fix:
exit might be faster than free, but valgrind warnings are ugly
[24 Jun 2010 8:20] MySQL Verification Team
full valgrind output.

Attachment: bug54764_5.5.5_valgrind_output.txt (text/plain), 30.92 KiB.

[24 Jun 2010 8:41] MySQL Verification Team
looks like array->aio_ctx and array->aio_events are not freed in os_aio_array_free().
[24 Jun 2010 16:22] MySQL Verification Team
Thank you for the bug report. Verified on Slackware 13.1 X86_64:

100624 13:17:36  InnoDB: Starting shutdown...
100624 13:17:45  InnoDB: Shutdown completed; log sequence number 1595675
100624 13:17:45 [Note] ./bin/mysqld: Shutdown complete

--20674-- Discarding syms at 0x6c9c810-0x6cace08 in /usr/lib64/libgcc_s.so.1 due to munmap()
--20674-- Discarding syms at 0x1a35c140-0x1a364408 in /lib64/libnss_files-2.11.1.so due to munmap()
==20674== 
==20674== HEAP SUMMARY:
==20674==     in use at exit: 13,800 bytes in 11 blocks
==20674==   total heap usage: 57,523 allocs, 57,512 frees, 65,020,632 bytes allocated
==20674== 
<cut>
==20674== 
==20674== 4,096 bytes in 1 blocks are definitely lost in loss record 11 of 11
==20674==    at 0x4C25E13: malloc (in /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so)
==20674==    by 0x931BA0: ut_malloc_low (ut0mem.c:106)
==20674==    by 0x931E4B: ut_malloc (ut0mem.c:244)
==20674==    by 0x9A002F: os_aio_array_create (os0file.c:3261)
==20674==    by 0x9A029D: os_aio_init (os0file.c:3377)
==20674==    by 0x9194C5: innobase_start_or_create_for_mysql (srv0start.c:1329)
==20674==    by 0x8E3D89: innobase_init(void*) (ha_innodb.cc:2421)
==20674==    by 0x71E324: ha_initialize_handlerton(st_plugin_int*) (handler.cc:476)
==20674==    by 0x5C47CE: plugin_initialize(st_plugin_int*) (sql_plugin.cc:1052)
==20674==    by 0x5C5106: plugin_init(int*, char**, int) (sql_plugin.cc:1338)
==20674==    by 0x522160: init_server_components() (mysqld.cc:4171)
==20674==    by 0x522DE3: mysqld_main(int, char**) (mysqld.cc:4762)
==20674==    by 0x51C2BB: main (main.cc:24)
==20674== 
==20674== LEAK SUMMARY:
==20674==    definitely lost: 13,528 bytes in 10 blocks
==20674==    indirectly lost: 0 bytes in 0 blocks
==20674==      possibly lost: 272 bytes in 1 blocks
==20674==    still reachable: 0 bytes in 0 blocks
==20674==         suppressed: 0 bytes in 0 blocks
==20674== 
==20674== ERROR SUMMARY: 11 errors from 11 contexts (suppressed: 5 from 5)
--20674-- 
--20674-- used_suppression:      2 dl-hack3-cond-1
--20674-- used_suppression:      3 glibc-2.5.x-on-SUSE-10.2-(PPC)-2a
==20674== 
==20674== ERROR SUMMARY: 11 errors from 11 contexts (suppressed: 5 from 5)
[miguel@tikal 5.5mr]$
[30 Jun 2010 0:11] Omer Barnir
triage: setting to SR55RC  (minimum impact but should be fixed - Alik)
[7 Jul 2010 8:08] Jimmy Yang
This is related to the new libaio code. Two structure allocated under LINUX_NATIVE_AIO define in os_aio_array_create() is not freed os_aio_array_free():

   3245         array->aio_ctx = ut_malloc(n_segments *
   3246                                    sizeof(*array->aio_ctx));

   3261         io_event = ut_malloc(n * sizeof(*io_event));
   3262         memset(io_event, 0x0, sizeof(*io_event) * n);
   3263         array->aio_events = io_event;
[8 Jul 2010 7:07] 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/113091

3133 Jimmy Yang	2010-07-08
      Fix Bug #54764 memory allocated in os_aio_array_create is not
      freed at shutdown
      
      rb://395, approved by Sunny Bains
[4 Aug 2010 7:50] Bugs System
Pushed into mysql-trunk 5.5.6-m3 (revid:alik@sun.com-20100731131027-1n61gseejyxsqk5d) (version source revid:alik@sun.com-20100731074942-o840woifuqioxxe4) (merge vers: 5.5.6-m3) (pib:18)
[4 Aug 2010 7:55] Bugs System
Pushed into mysql-trunk 5.5.6-m3 (revid:alik@sun.com-20100731131027-1n61gseejyxsqk5d) (version source revid:alik@sun.com-20100731074942-o840woifuqioxxe4) (merge vers: 5.5.6-m3) (pib:18)
[4 Aug 2010 7:56] Bugs System
Pushed into mysql-trunk 5.5.6-m3 (revid:alik@sun.com-20100731131027-1n61gseejyxsqk5d) (version source revid:alik@sun.com-20100731074942-o840woifuqioxxe4) (merge vers: 5.5.6-m3) (pib:18)
[4 Aug 2010 7:57] Bugs System
Pushed into mysql-trunk 5.5.6-m3 (revid:alik@sun.com-20100731131027-1n61gseejyxsqk5d) (version source revid:alik@sun.com-20100731074942-o840woifuqioxxe4) (merge vers: 5.5.6-m3) (pib:18)
[4 Aug 2010 7:58] Bugs System
Pushed into mysql-trunk 5.5.6-m3 (revid:alik@sun.com-20100731131027-1n61gseejyxsqk5d) (version source revid:alik@sun.com-20100731074942-o840woifuqioxxe4) (merge vers: 5.5.6-m3) (pib:18)
[4 Aug 2010 7:59] Bugs System
Pushed into mysql-trunk 5.5.6-m3 (revid:alik@sun.com-20100731131027-1n61gseejyxsqk5d) (version source revid:alik@sun.com-20100731074942-o840woifuqioxxe4) (merge vers: 5.5.6-m3) (pib:18)
[4 Aug 2010 8:00] Bugs System
Pushed into mysql-trunk 5.5.6-m3 (revid:alik@sun.com-20100731131027-1n61gseejyxsqk5d) (version source revid:alik@sun.com-20100731074942-o840woifuqioxxe4) (merge vers: 5.5.6-m3) (pib:18)
[4 Aug 2010 8:03] Bugs System
Pushed into mysql-trunk 5.6.1-m4 (revid:alik@ibmvm-20100804080001-bny5271e65xo34ig) (version source revid:alik@sun.com-20100731075120-qz9z8c25zum2wgmm) (merge vers: 5.6.99-m4) (pib:18)
[4 Aug 2010 8:13] Bugs System
Pushed into mysql-trunk 5.6.1-m4 (revid:alik@ibmvm-20100804080001-bny5271e65xo34ig) (version source revid:alik@sun.com-20100731075120-qz9z8c25zum2wgmm) (merge vers: 5.6.99-m4) (pib:18)
[4 Aug 2010 8:14] Bugs System
Pushed into mysql-trunk 5.6.1-m4 (revid:alik@ibmvm-20100804080001-bny5271e65xo34ig) (version source revid:alik@sun.com-20100731075120-qz9z8c25zum2wgmm) (merge vers: 5.6.99-m4) (pib:18)
[4 Aug 2010 8:15] Bugs System
Pushed into mysql-trunk 5.6.1-m4 (revid:alik@ibmvm-20100804080001-bny5271e65xo34ig) (version source revid:alik@sun.com-20100731075120-qz9z8c25zum2wgmm) (merge vers: 5.6.99-m4) (pib:18)
[4 Aug 2010 8:16] Bugs System
Pushed into mysql-trunk 5.6.1-m4 (revid:alik@ibmvm-20100804080001-bny5271e65xo34ig) (version source revid:alik@sun.com-20100731075120-qz9z8c25zum2wgmm) (merge vers: 5.6.99-m4) (pib:18)
[4 Aug 2010 8:17] Bugs System
Pushed into mysql-trunk 5.6.1-m4 (revid:alik@ibmvm-20100804080001-bny5271e65xo34ig) (version source revid:alik@sun.com-20100731075120-qz9z8c25zum2wgmm) (merge vers: 5.6.99-m4) (pib:18)
[4 Aug 2010 8:19] Bugs System
Pushed into mysql-trunk 5.6.1-m4 (revid:alik@ibmvm-20100804081533-c1d3rbipo9e8rt1s) (version source revid:alik@sun.com-20100731075120-qz9z8c25zum2wgmm) (merge vers: 5.6.99-m4) (pib:18)
[4 Aug 2010 9:00] Bugs System
Pushed into mysql-trunk 5.6.1-m4 (revid:alik@ibmvm-20100804081533-c1d3rbipo9e8rt1s) (version source revid:alik@sun.com-20100731075120-qz9z8c25zum2wgmm) (merge vers: 5.6.99-m4) (pib:20)
[4 Aug 2010 9:01] Bugs System
Pushed into mysql-next-mr (revid:alik@ibmvm-20100804081630-ntapn8bf9pko9vj3) (version source revid:alik@sun.com-20100731075120-qz9z8c25zum2wgmm) (pib:20)
[25 Aug 2010 16:47] Calvin Sun
fix in 5.5.6.
[14 Sep 2010 18:03] John Russell
Added entry to the change log:

Some memory used for InnoDB asynchronous I/O was not freed at shutdown.