Bug #54744 valgrind reports leak for mysqlbinlog
Submitted: 23 Jun 2010 15:34 Modified: 6 Aug 2010 14:58
Reporter: Luis Soares Email Updates:
Status: Closed Impact on me:
None 
Category:MySQL Server: Replication Severity:S3 (Non-critical)
Version:trunk OS:Any
Assigned to: Luis Soares CPU Architecture:Any

[23 Jun 2010 15:34] Luis Soares
Description:
valgrind issues the following warnings if mysqlbinlog is 
called without any parameters:

==20983== 
==20983== ERROR SUMMARY: 0 errors from 0 contexts (suppressed: 5 from 1)
==20983== malloc/free: in use at exit: 1,912 bytes in 7 blocks.
==20983== malloc/free: 25 allocs, 18 frees, 5,572 bytes allocated.
==20983== For counts of detected errors, rerun with: -v
==20983== searching for pointers to 7 not-freed blocks.
==20983== checked 2,648,104 bytes.
==20983== 
==20983== LEAK SUMMARY:
==20983==    definitely lost: 0 bytes in 0 blocks.
==20983==      possibly lost: 0 bytes in 0 blocks.
==20983==    still reachable: 1,912 bytes in 7 blocks.
==20983==         suppressed: 0 bytes in 0 blocks.

Environment details:

    tree: mysql-trunk-bugfixing
   revid: revision-id: joerg@mysql.com-20100623143203-btlp7s33lq2fqizm
valgrind: valgrind-3.2.1
    host: fimafeng11
      OS: Linux
     gcc: gcc (GCC) 4.1.2 20070626 (Red Hat 4.1.2-14)

How to repeat:
1. bzr clone -r revid:joerg@mysql.com-20100623143203-btlp7s33lq2fqizm mysql-trunk-bugfixing BZR_REPO/mysql-trunk-bugfixing
2. cd mysql-trunk-bugfixing
3. bash BUILD/compile-amd64-valgrind-max
4. valgrind client/mysqlbinlog

(for additional info)

5. valgrind --tool=memcheck --leak-check=full --show-reachable=yes -v client/mysqlbinlog

Suggested fix:
.
[23 Jun 2010 20:02] Valeriy Kravchuk
Verified just as described on Mac OS X:

...
==98366== ERROR SUMMARY: 0 errors from 0 contexts (suppressed: 0 from 0)
==98366== malloc/free: in use at exit: 14,537 bytes in 17 blocks.
==98366== malloc/free: 19 allocs, 2 frees, 15,053 bytes allocated.
==98366== 
==98366== searching for pointers to 17 not-freed blocks.
......................==98366== checked 6,241,840 bytes.

...

==98366== ERROR
==98366== 
==98366== 
==98366== 7,900 bytes in 1 blocks are still reachable in loss record 10 of 10
==98366==    at 0x4CE53: malloc+99 (in /usr/local/lib/valgrind/x86-darwin/vgpreload_memcheck.so)
==98366==    by 0x7CF695: tzsetwall_basic+65 (in /usr/lib/libSystem.B.dylib)
==98366==    by 0x7EF999: localtime_r+54 (in /usr/lib/libSystem.B.dylib)
==98366==    by 0x41A806: my_init_time+44 (in /Users/openxs/dbs/trunk/lib/mysql/libmysqlclient.16.dylib)
==98366==    by 0x1B941: main+95 (in bin/mysqlbinlog)
==98366== 
==98366== LEAK SUMMARY:
==98366==    definitely lost: 0 bytes in 0 blocks.
==98366==      possibly lost: 0 bytes in 0 blocks.
==98366==    still reachable: 14,537 bytes in 17 blocks.
==98366==         suppressed: 0 bytes in 0 blocks.
...
[6 Jul 2010 22:33] Luis Soares
On my local environment I get:

valgrind --tool=memcheck --leak-check=full --show-reachable=yes -v client/mysqlbinlog

==21158== HEAP SUMMARY:
==21158==     in use at exit: 368 bytes in 2 blocks
==21158==   total heap usage: 36 allocs, 34 frees, 47,524 bytes allocated
==21158== 
==21158== Searching for pointers to 2 not-freed blocks
==21158== Checked 2,638,152 bytes
==21158== 
==21158== 88 bytes in 1 blocks are still reachable in loss record 1 of 2
==21158==    at 0x4C284A8: malloc (vg_replace_malloc.c:236)
==21158==    by 0x4420C1: DbugMalloc (dbug.c:2183)
==21158==    by 0x43E525: code_state (dbug.c:397)
==21158==    by 0x4408D6: _db_enter_ (dbug.c:1152)
==21158==    by 0x46AF4C: dirname_part (mf_dirname.c:70)
==21158==    by 0x460C9E: intern_filename (mf_pack.c:525)
==21158==    by 0x45A090: my_basic_init (my_init.c:123)
==21158==    by 0x45A0D0: my_init (my_init.c:146)
==21158==    by 0x40CDFB: main (mysqlbinlog.cc:2020)
==21158== 
==21158== 280 bytes in 1 blocks are still reachable in loss record 2 of 2
==21158==    at 0x4C277CC: calloc (vg_replace_malloc.c:467)
==21158==    by 0x46815F: my_thread_init (my_thr_init.c:352)
==21158==    by 0x467A61: my_thread_basic_global_init (my_thr_init.c:126)
==21158==    by 0x467CAD: my_thread_global_init (my_thr_init.c:185)
==21158==    by 0x45A02F: my_basic_init (my_init.c:103)
==21158==    by 0x45A0D0: my_init (my_init.c:146)
==21158==    by 0x40CDFB: main (mysqlbinlog.cc:2020)
==21158== 
==21158== LEAK SUMMARY:
==21158==    definitely lost: 0 bytes in 0 blocks
==21158==    indirectly lost: 0 bytes in 0 blocks
==21158==      possibly lost: 0 bytes in 0 blocks
==21158==    still reachable: 368 bytes in 2 blocks
==21158==         suppressed: 0 bytes in 0 blocks
==21158== 
==21158== ERROR SUMMARY: 0 errors from 0 contexts (suppressed: 4 from 4)
--21158-- 
--21158-- used_suppression:      2 dl-hack3-cond-1
--21158-- used_suppression:      2 glibc-2.5.x-on-SUSE-10.2-(PPC)-2a
==21158==
[6 Jul 2010 22:42] 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/112981

3085 Luis Soares	2010-07-06
      BUG#54744: valgrind reports leak for mysqlbinlog
      
      The server was not cleaning up dbug allocated memory before
      exiting. This is not a real problem, as this memory would be
      deallocated anyway. Nonetheless, we improve the mysqlbinlog exit
      procedure, wrt to memory book-keeping, when no parameter is
      given.
      
      To fix this, we deploy a call to my_thread_end() before the
      thread exits, which will also free pending dbug related allocated
      blocks.
[6 Jul 2010 22:48] Luis Soares
My env:
 - ubuntu    10.04
 - valgrind: valgrind-3.6.0.SVN-Debian
 - arch:     x86_64
 - gcc:      gcc (Ubuntu 4.4.3-4ubuntu5) 4.4.3

After patching mysqlbinlog.cc with the patch above, I get:

$ valgrind --tool=memcheck --leak-check=full --show-reachable=yes -v client/mysqlbinlog

(...)

==23685== 
==23685== HEAP SUMMARY:
==23685==     in use at exit: 0 bytes in 0 blocks
==23685==   total heap usage: 36 allocs, 36 frees, 47,524 bytes allocated
==23685== 
==23685== All heap blocks were freed -- no leaks are possible
==23685== 
==23685== ERROR SUMMARY: 0 errors from 0 contexts (suppressed: 4 from 4)
--23685-- 
--23685-- used_suppression:      2 dl-hack3-cond-1
--23685-- used_suppression:      2 glibc-2.5.x-on-SUSE-10.2-(PPC)-2a
==23685== 
==23685== ERROR SUMMARY: 0 errors from 0 contexts (suppressed: 4 from 4)
[8 Jul 2010 9:29] Luis Soares
Queued in mysql-trunk-bugfixing and merged to mysql-next-mr-bugfixing:
- http://pb2.norway.sun.com/web.py?template=push_details&push=1402801
- http://pb2.norway.sun.com/web.py?template=push_details&push=1402747
[8 Jul 2010 16:26] 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/113161

3100 Luis Soares	2010-07-08
      Revert patch for BUG#54744.
[8 Jul 2010 22:41] 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/113186

3102 Luis Soares	2010-07-08
      BUG#54744: valgrind reports leak for mysqlbinlog
            
      The server was not cleaning up some dbug allocated memory 
      before exiting. This is not a real problem, as this memory 
      would be deallocated anyway. Nonetheless, we improve the 
      mysqlbinlog exit procedure, wrt to memory book-keeping, when 
      no parameter is given.
            
      To fix this, we deploy a call to my_end() before the
      thread exits.
[9 Jul 2010 11:45] Luis Soares
Queued in mysql-trunk-bugfixing and merged to mysql-next-mr-bugfixing:
- http://pb2.norway.sun.com/web.py?template=push_details&push=1406089
- http://pb2.norway.sun.com/web.py?template=push_details&push=1406084
[23 Jul 2010 12:28] Bugs System
Pushed into mysql-trunk 5.5.6-m3 (revid:alik@sun.com-20100723121820-jryu2fuw3pc53q9w) (version source revid:vasil.dimov@oracle.com-20100531152341-x2d4hma644icamh1) (merge vers: 5.5.5-m3) (pib:18)
[23 Jul 2010 12:35] Bugs System
Pushed into mysql-next-mr (revid:alik@sun.com-20100723121929-90e9zemk3jkr2ocy) (version source revid:vasil.dimov@oracle.com-20100531152341-x2d4hma644icamh1) (pib:18)
[6 Aug 2010 14:58] Jon Stephens
No user-visible changes to document. Closed without further action.