Bug #81215 Memory leak in main.udf
Submitted: 27 Apr 2016 20:42 Modified: 28 Jun 2016 9:38
Reporter: Manuel Ung Email Updates:
Status: Can't repeat Impact on me:
None 
Category:MySQL Server: User-defined functions ( UDF ) Severity:S3 (Non-critical)
Version:5.6 OS:Linux
Assigned to: CPU Architecture:Any

[27 Apr 2016 20:42] Manuel Ung
Description:
The main.udf test occasionally fails in valgrind when calling dlclose on the loaded so file.

 32 bytes in 1 blocks are still reachable in loss record 4 of 8
    at 0x4C2D08A: calloc (in /lib/valgrind/vgpreload_memcheck-amd64-linux.so)
    by 0x66277BE: _dlerror_run (in /lib/libdl-2.20.so)
    by 0x662716E: dlclose (in /lib/libdl-2.20.so)
    by 0xD0229B: udf_free() (sql_udf.cc:273)
    by 0xA8A37B: clean_up(bool) (mysqld.cc:2094)
    by 0xA89F3D: unireg_end() (mysqld.cc:1951)
    by 0xA89E88: kill_server(void*) (mysqld.cc:1879)
    by 0xA89EA5: kill_server_thread (mysqld.cc:1902)
    by 0x529A7F0: start_thread (in /lib/libpthread-2.20.so)
    by 0x6F7046C: clone (in /lib/libc-2.20.so)

It seems like the same problem was occurring for unloaded plugins as well. There should be an analogous fix for udfs.
https://github.com/mysql/mysql-server/blob/5.7/mysql-test/valgrind.supp#L919-L931

The same bug was reported here: https://bugs.mysql.com/bug.php?id=35590
However, it was committed to 6.0 and for some reason, it was not backported to the 5.x releases.

How to repeat:
It's hard to repro, but: 
./mtr --valgrind main.udf

Suggested fix:
Backport this fix:
http://lists.mysql.com/commits/44571
[28 Apr 2016 10:37] MySQL Verification Team
Thank you for the bug report.

LEAK SUMMARY:
   definitely lost: 0 bytes in 0 blocks
   indirectly lost: 0 bytes in 0 blocks
     possibly lost: 576 bytes in 1 blocks
   still reachable: 72,704 bytes in 1 blocks
        suppressed: 67,917,725 bytes in 1,373 blocks

For counts of detected and suppressed errors, rerun with: -v
ERROR SUMMARY: 1 errors from 1 contexts (suppressed: 324 from 324)

valgrind_report                          [ fail ]
        Test ended at 2016-04-27 19:36:16
[28 Jun 2016 9:38] Arun Kuruvila
This bug is not reproducible on 5.6. Hence closing this bug
as "Can't repeat". However the issue was seen in 5.7 which
was fixed in 5.7.4