Bug #98905 possible memory leak with libmysqlclient.so

Submitted: 11 Mar 2020 10:14 Modified: 11 Mar 2020 14:06
Reporter: lalit Choudhary Email Updates:
Status: Not a Bug Impact on me:
None 
Category:MySQL Server: C API (client library) Severity:S3 (Non-critical)
Version:5.7.29 OS:Any
Assigned to: CPU Architecture:Any

[11 Mar 2020 10:14] lalit Choudhary
Description:
possible memory leak with libmysqlclient.so   as per the valgrind report.

==958==    by 0x108769: main (mysql_dlopen.c:11)
==958== 
==958== LEAK SUMMARY:
==958==    definitely lost: 0 bytes in 0 blocks
==958==    indirectly lost: 0 bytes in 0 blocks
==958==      possibly lost: 0 bytes in 0 blocks
==958==    still reachable: 86,098 bytes in 27 blocks
==958==         suppressed: 0 bytes in 0 blocks
==958== 
==958== ERROR SUMMARY: 0 errors from 0 contexts (suppressed: 0 from 0)
==958== ERROR SUMMARY: 0 errors from 0 contexts (suppressed: 0 from 0)

It has ==958==    still reachable: 86,098 bytes in 27 blocks

"Reachable block" memory that was not freed, but a pointer to it still exists at the program's exit time.

How to repeat:
********************
mysql_dlopen.c
********************
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <dlfcn.h>
void *mysql_handle;

int main()
{
mysql_handle = NULL;

mysql_handle = dlopen("/home/lalit/mysql_tar/mysql/5.7.29/lib/libmysqlclient.so", RTLD_NOW | RTLD_DEEPBIND);
if (!mysql_handle)

{
printf("Failed to open handle :%s\n", dlerror());
}

if (mysql_handle != NULL)
{
dlclose(mysql_handle);
mysql_handle = NULL;
}
return 0;
}

********

mysql/5.7.29/lib$ g++ mysql_dlopen.c -Wall -ggdb3  -ldl -o mysql_dlopen

$ valgrind --leak-check=full --show-leak-kinds=all --track-origins=yes --verbose ./mysql_dlopen
==958== Memcheck, a memory error detector
==958== Copyright (C) 2002-2017, and GNU GPL'd, by Julian Seward et al.
==958== Using Valgrind-3.13.0 and LibVEX; rerun with -h for copyright info
==958== Command: ./mysql_dlopen
==958== 
--958-- Valgrind options:
--958--    --leak-check=full
--958--    --show-leak-kinds=all
--958--    --track-origins=yes
--958--    --verbose
--958-- Contents of /proc/version:
--958--   Linux version 4.15.0-76-generic (buildd@lcy01-amd64-029) (gcc version 7.4.0 (Ubuntu 7.4.0-1ubuntu1~18.04.1)) #86-Ubuntu SMP Fri Jan 17 17:24:28 UTC 2020
--958-- 
--958-- Arch and hwcaps: AMD64, LittleEndian, amd64-cx16-lzcnt-rdtscp-sse3-avx-avx2-bmi
--958-- Page sizes: currently 4096, max supported 4096
--958-- Valgrind library directory: /usr/lib/valgrind
--958-- Reading syms from /home/lalit/mysql_tar/mysql/5.7.29/lib/mysql_dlopen
--958-- Reading syms from /lib/x86_64-linux-gnu/ld-2.27.so
--958--   Considering /lib/x86_64-linux-gnu/ld-2.27.so ..
--958--   .. CRC mismatch (computed 1b7c895e wanted 2943108a)
--958--   Considering /usr/lib/debug/lib/x86_64-linux-gnu/ld-2.27.so ..
--958--   .. CRC is valid
--958-- Reading syms from /usr/lib/valgrind/memcheck-amd64-linux
--958--   Considering /usr/lib/valgrind/memcheck-amd64-linux ..
--958--   .. CRC mismatch (computed c25f395c wanted 0a9602a8)
--958--    object doesn't have a symbol table
--958--    object doesn't have a dynamic symbol table
--958-- Scheduler: using generic scheduler lock implementation.
--958-- Reading suppressions file: /usr/lib/valgrind/default.supp
==958== embedded gdbserver: reading from /tmp/vgdb-pipe-from-vgdb-to-958-by-lalit-on-???
==958== embedded gdbserver: writing to   /tmp/vgdb-pipe-to-vgdb-from-958-by-lalit-on-???
==958== embedded gdbserver: shared mem   /tmp/vgdb-pipe-shared-mem-vgdb-958-by-lalit-on-???
==958== 
==958== TO CONTROL THIS PROCESS USING vgdb (which you probably
==958== don't want to do, unless you know exactly what you're doing,
==958== or are doing some strange experiment):
==958==   /usr/lib/valgrind/../../bin/vgdb --pid=958 ...command...
==958== 
==958== TO DEBUG THIS PROCESS USING GDB: start GDB like this
==958==   /path/to/gdb ./mysql_dlopen
==958== and then give GDB the following command
==958==   target remote | /usr/lib/valgrind/../../bin/vgdb --pid=958
==958== --pid is optional if only one valgrind process is running
==958== 
--958-- REDIR: 0x401f2f0 (ld-linux-x86-64.so.2:strlen) redirected to 0x58060901 (???)
--958-- REDIR: 0x401f0d0 (ld-linux-x86-64.so.2:index) redirected to 0x5806091b (???)
--958-- Reading syms from /usr/lib/valgrind/vgpreload_core-amd64-linux.so
--958--   Considering /usr/lib/valgrind/vgpreload_core-amd64-linux.so ..
--958--   .. CRC mismatch (computed 4b63d83e wanted 670599e6)
--958--    object doesn't have a symbol table
--958-- Reading syms from /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so
--958--   Considering /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so ..
--958--   .. CRC mismatch (computed a4b37bee wanted 8ad4dc94)
--958--    object doesn't have a symbol table
==958== WARNING: new redirection conflicts with existing -- ignoring it
--958--     old: 0x0401f2f0 (strlen              ) R-> (0000.0) 0x58060901 ???
--958--     new: 0x0401f2f0 (strlen              ) R-> (2007.0) 0x04c32db0 strlen
--958-- REDIR: 0x401d360 (ld-linux-x86-64.so.2:strcmp) redirected to 0x4c33ee0 (strcmp)
--958-- REDIR: 0x401f830 (ld-linux-x86-64.so.2:mempcpy) redirected to 0x4c374f0 (mempcpy)
--958-- Reading syms from /lib/x86_64-linux-gnu/libdl-2.27.so
--958--   Considering /lib/x86_64-linux-gnu/libdl-2.27.so ..
--958--   .. CRC mismatch (computed bd82fa02 wanted d1fdccc9)
--958--   Considering /usr/lib/debug/lib/x86_64-linux-gnu/libdl-2.27.so ..
--958--   .. CRC is valid
--958-- Reading syms from /lib/x86_64-linux-gnu/libc-2.27.so
--958--   Considering /lib/x86_64-linux-gnu/libc-2.27.so ..
--958--   .. CRC mismatch (computed b1c74187 wanted 042cc048)
--958--   Considering /usr/lib/debug/lib/x86_64-linux-gnu/libc-2.27.so ..
--958--   .. CRC is valid
--958-- REDIR: 0x50dec70 (libc.so.6:memmove) redirected to 0x4a2a6e0 (_vgnU_ifunc_wrapper)
--958-- REDIR: 0x50ddd40 (libc.so.6:strncpy) redirected to 0x4a2a6e0 (_vgnU_ifunc_wrapper)
--958-- REDIR: 0x50def50 (libc.so.6:strcasecmp) redirected to 0x4a2a6e0 (_vgnU_ifunc_wrapper)
--958-- REDIR: 0x50dd790 (libc.so.6:strcat) redirected to 0x4a2a6e0 (_vgnU_ifunc_wrapper)
--958-- REDIR: 0x50ddd70 (libc.so.6:rindex) redirected to 0x4a2a6e0 (_vgnU_ifunc_wrapper)
--958-- REDIR: 0x50e07c0 (libc.so.6:rawmemchr) redirected to 0x4a2a6e0 (_vgnU_ifunc_wrapper)
--958-- REDIR: 0x50dede0 (libc.so.6:mempcpy) redirected to 0x4a2a6e0 (_vgnU_ifunc_wrapper)
--958-- REDIR: 0x50dec10 (libc.so.6:bcmp) redirected to 0x4a2a6e0 (_vgnU_ifunc_wrapper)
--958-- REDIR: 0x50ddd00 (libc.so.6:strncmp) redirected to 0x4a2a6e0 (_vgnU_ifunc_wrapper)
--958-- REDIR: 0x50dd800 (libc.so.6:strcmp) redirected to 0x4a2a6e0 (_vgnU_ifunc_wrapper)
--958-- REDIR: 0x50ded40 (libc.so.6:memset) redirected to 0x4a2a6e0 (_vgnU_ifunc_wrapper)
--958-- REDIR: 0x50fc0f0 (libc.so.6:wcschr) redirected to 0x4a2a6e0 (_vgnU_ifunc_wrapper)
--958-- REDIR: 0x50ddca0 (libc.so.6:strnlen) redirected to 0x4a2a6e0 (_vgnU_ifunc_wrapper)
--958-- REDIR: 0x50dd870 (libc.so.6:strcspn) redirected to 0x4a2a6e0 (_vgnU_ifunc_wrapper)
--958-- REDIR: 0x50defa0 (libc.so.6:strncasecmp) redirected to 0x4a2a6e0 (_vgnU_ifunc_wrapper)
--958-- REDIR: 0x50dd840 (libc.so.6:strcpy) redirected to 0x4a2a6e0 (_vgnU_ifunc_wrapper)
--958-- REDIR: 0x50df0e0 (libc.so.6:memcpy@@GLIBC_2.14) redirected to 0x4a2a6e0 (_vgnU_ifunc_wrapper)
--958-- REDIR: 0x50ddda0 (libc.so.6:strpbrk) redirected to 0x4a2a6e0 (_vgnU_ifunc_wrapper)
--958-- REDIR: 0x50dd7c0 (libc.so.6:index) redirected to 0x4a2a6e0 (_vgnU_ifunc_wrapper)
--958-- REDIR: 0x50ddc70 (libc.so.6:strlen) redirected to 0x4a2a6e0 (_vgnU_ifunc_wrapper)
--958-- REDIR: 0x50e86c0 (libc.so.6:memrchr) redirected to 0x4a2a6e0 (_vgnU_ifunc_wrapper)
--958-- REDIR: 0x50deff0 (libc.so.6:strcasecmp_l) redirected to 0x4a2a6e0 (_vgnU_ifunc_wrapper)
--958-- REDIR: 0x50debe0 (libc.so.6:memchr) redirected to 0x4a2a6e0 (_vgnU_ifunc_wrapper)
--958-- REDIR: 0x50fceb0 (libc.so.6:wcslen) redirected to 0x4a2a6e0 (_vgnU_ifunc_wrapper)
--958-- REDIR: 0x50de050 (libc.so.6:strspn) redirected to 0x4a2a6e0 (_vgnU_ifunc_wrapper)
--958-- REDIR: 0x50def20 (libc.so.6:stpncpy) redirected to 0x4a2a6e0 (_vgnU_ifunc_wrapper)
--958-- REDIR: 0x50deef0 (libc.so.6:stpcpy) redirected to 0x4a2a6e0 (_vgnU_ifunc_wrapper)
--958-- REDIR: 0x50e07f0 (libc.so.6:strchrnul) redirected to 0x4a2a6e0 (_vgnU_ifunc_wrapper)
--958-- REDIR: 0x50df040 (libc.so.6:strncasecmp_l) redirected to 0x4a2a6e0 (_vgnU_ifunc_wrapper)
--958-- REDIR: 0x51ce3c0 (libc.so.6:__strrchr_avx2) redirected to 0x4c32730 (rindex)
--958-- REDIR: 0x50d7070 (libc.so.6:malloc) redirected to 0x4c2faa0 (malloc)
--958-- REDIR: 0x50da030 (libc.so.6:calloc) redirected to 0x4c31a70 (calloc)
--958-- Reading syms from /home/lalit/mysql_tar/mysql/5.7.29/lib/libmysqlclient.so.20.3.16
--958-- Reading syms from /lib/x86_64-linux-gnu/libpthread-2.27.so
--958--   Considering /usr/lib/debug/.build-id/28/c6aade70b2d40d1f0f3d0a1a0cad1ab816448f.debug ..
--958--   .. build-id is valid
--958-- Reading syms from /lib/x86_64-linux-gnu/librt-2.27.so
--958--   Considering /lib/x86_64-linux-gnu/librt-2.27.so ..
--958--   .. CRC mismatch (computed 16979484 wanted f9e041e3)
--958--   Considering /usr/lib/debug/lib/x86_64-linux-gnu/librt-2.27.so ..
--958--   .. CRC is valid
--958-- Reading syms from /usr/lib/x86_64-linux-gnu/libstdc++.so.6.0.25
--958--    object doesn't have a symbol table
--958-- Reading syms from /lib/x86_64-linux-gnu/libm-2.27.so
--958--   Considering /lib/x86_64-linux-gnu/libm-2.27.so ..
--958--   .. CRC mismatch (computed 7feae033 wanted b29b2508)
--958--   Considering /usr/lib/debug/lib/x86_64-linux-gnu/libm-2.27.so ..
--958--   .. CRC is valid
--958-- Reading syms from /lib/x86_64-linux-gnu/libgcc_s.so.1
--958--    object doesn't have a symbol table
--958-- REDIR: 0x50d7950 (libc.so.6:free) redirected to 0x4c30cd0 (free)
--958-- REDIR: 0x50deb20 (libc.so.6:strstr) redirected to 0x4a2a6e0 (_vgnU_ifunc_wrapper)
--958-- REDIR: 0x50ddcd0 (libc.so.6:strncat) redirected to 0x4a2a6e0 (_vgnU_ifunc_wrapper)
--958-- Discarding syms at 0x5895ad0-0x5a64628 in /home/lalit/mysql_tar/mysql/5.7.29/lib/libmysqlclient.so.20.3.16 due to munmap()
==958== 
==958== HEAP SUMMARY:
==958==     in use at exit: 86,098 bytes in 27 blocks
==958==   total heap usage: 39 allocs, 12 frees, 91,189 bytes allocated
==958== 
==958== Searching for pointers to 27 not-freed blocks
==958== Checked 145,304 bytes
==958== 
==958== 160 bytes in 5 blocks are still reachable in loss record 1 of 7
==958==    at 0x4C2FB0F: malloc (in /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so)
==958==    by 0x4016027: _dl_close_worker.part.0 (dl-close.c:395)
==958==    by 0x4016AA9: _dl_close_worker (dl-close.c:125)
==958==    by 0x4016AA9: _dl_close (dl-close.c:842)
==958==    by 0x51A72DE: _dl_catch_exception (dl-error-skeleton.c:196)
==958==    by 0x51A736E: _dl_catch_error (dl-error-skeleton.c:215)
==958==    by 0x4E3D734: _dlerror_run (dlerror.c:162)
==958==    by 0x4E3D0B2: dlclose (dlclose.c:46)
==958==    by 0x1087B0: main (mysql_dlopen.c:20)
==958== 
==958== 180 bytes in 5 blocks are still reachable in loss record 2 of 7
==958==    at 0x4C2FB0F: malloc (in /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so)
==958==    by 0x401D329: strdup (strdup.c:42)
==958==    by 0x4018656: _dl_load_cache_lookup (dl-cache.c:315)
==958==    by 0x4009382: _dl_map_object (dl-load.c:2255)
==958==    by 0x400E311: openaux (dl-deps.c:63)
==958==    by 0x51A72DE: _dl_catch_exception (dl-error-skeleton.c:196)
==958==    by 0x400E617: _dl_map_object_deps (dl-deps.c:249)
==958==    by 0x4014F48: dl_open_worker (dl-open.c:278)
==958==    by 0x51A72DE: _dl_catch_exception (dl-error-skeleton.c:196)
==958==    by 0x40147C9: _dl_open (dl-open.c:605)
==958==    by 0x4E3CF95: dlopen_doit (dlopen.c:66)
==958==    by 0x51A72DE: _dl_catch_exception (dl-error-skeleton.c:196)
==958== 
==958== 180 bytes in 5 blocks are still reachable in loss record 3 of 7
==958==    at 0x4C2FB0F: malloc (in /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so)
==958==    by 0x400C3E7: _dl_new_object (dl-object.c:163)
==958==    by 0x40069A4: _dl_map_object_from_fd (dl-load.c:943)
==958==    by 0x4008FFB: _dl_map_object (dl-load.c:2389)
==958==    by 0x400E311: openaux (dl-deps.c:63)
==958==    by 0x51A72DE: _dl_catch_exception (dl-error-skeleton.c:196)
==958==    by 0x400E617: _dl_map_object_deps (dl-deps.c:249)
==958==    by 0x4014F48: dl_open_worker (dl-open.c:278)
==958==    by 0x51A72DE: _dl_catch_exception (dl-error-skeleton.c:196)
==958==    by 0x40147C9: _dl_open (dl-open.c:605)
==958==    by 0x4E3CF95: dlopen_doit (dlopen.c:66)
==958==    by 0x51A72DE: _dl_catch_exception (dl-error-skeleton.c:196)
==958== 
==958== 2,904 bytes in 5 blocks are still reachable in loss record 4 of 7
==958==    at 0x4C31B25: calloc (in /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so)
==958==    by 0x4011E85: _dl_check_map_versions (dl-version.c:274)
==958==    by 0x401524B: dl_open_worker (dl-open.c:284)
==958==    by 0x51A72DE: _dl_catch_exception (dl-error-skeleton.c:196)
==958==    by 0x40147C9: _dl_open (dl-open.c:605)
==958==    by 0x4E3CF95: dlopen_doit (dlopen.c:66)
==958==    by 0x51A72DE: _dl_catch_exception (dl-error-skeleton.c:196)
==958==    by 0x51A736E: _dl_catch_error (dl-error-skeleton.c:215)
==958==    by 0x4E3D734: _dlerror_run (dlerror.c:162)
==958==    by 0x4E3D050: dlopen@@GLIBC_2.2.5 (dlopen.c:87)
==958==    by 0x108769: main (mysql_dlopen.c:11)
==958== 
==958== 4,064 bytes in 1 blocks are still reachable in loss record 5 of 7
==958==    at 0x4C31B25: calloc (in /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so)
==958==    by 0x400ACF9: do_lookup_unique (dl-lookup.c:251)
==958==    by 0x400ACF9: do_lookup_x (dl-lookup.c:527)
==958==    by 0x400B1EE: _dl_lookup_symbol_x (dl-lookup.c:813)
==958==    by 0x400CAF8: elf_machine_rela (dl-machine.h:308)
==958==    by 0x400CAF8: elf_dynamic_do_Rela (do-rel.h:137)
==958==    by 0x400CAF8: _dl_relocate_object (dl-reloc.c:258)
==958==    by 0x40150BC: dl_open_worker (dl-open.c:382)
==958==    by 0x51A72DE: _dl_catch_exception (dl-error-skeleton.c:196)
==958==    by 0x40147C9: _dl_open (dl-open.c:605)
==958==    by 0x4E3CF95: dlopen_doit (dlopen.c:66)
==958==    by 0x51A72DE: _dl_catch_exception (dl-error-skeleton.c:196)
==958==    by 0x51A736E: _dl_catch_error (dl-error-skeleton.c:215)
==958==    by 0x4E3D734: _dlerror_run (dlerror.c:162)
==958==    by 0x4E3D050: dlopen@@GLIBC_2.2.5 (dlopen.c:87)
==958== 
==958== 5,906 bytes in 5 blocks are still reachable in loss record 6 of 7
==958==    at 0x4C31B25: calloc (in /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so)
==958==    by 0x400C100: _dl_new_object (dl-object.c:73)
==958==    by 0x40069A4: _dl_map_object_from_fd (dl-load.c:943)
==958==    by 0x4008FFB: _dl_map_object (dl-load.c:2389)
==958==    by 0x400E311: openaux (dl-deps.c:63)
==958==    by 0x51A72DE: _dl_catch_exception (dl-error-skeleton.c:196)
==958==    by 0x400E617: _dl_map_object_deps (dl-deps.c:249)
==958==    by 0x4014F48: dl_open_worker (dl-open.c:278)
==958==    by 0x51A72DE: _dl_catch_exception (dl-error-skeleton.c:196)
==958==    by 0x40147C9: _dl_open (dl-open.c:605)
==958==    by 0x4E3CF95: dlopen_doit (dlopen.c:66)
==958==    by 0x51A72DE: _dl_catch_exception (dl-error-skeleton.c:196)
==958== 
==958== 72,704 bytes in 1 blocks are still reachable in loss record 7 of 7
==958==    at 0x4C2FB0F: malloc (in /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so)
==958==    by 0x6529415: ??? (in /usr/lib/x86_64-linux-gnu/libstdc++.so.6.0.25)
==958==    by 0x4010732: call_init (dl-init.c:72)
==958==    by 0x4010732: _dl_init (dl-init.c:119)
==958==    by 0x40151FE: dl_open_worker (dl-open.c:522)
==958==    by 0x51A72DE: _dl_catch_exception (dl-error-skeleton.c:196)
==958==    by 0x40147C9: _dl_open (dl-open.c:605)
==958==    by 0x4E3CF95: dlopen_doit (dlopen.c:66)
==958==    by 0x51A72DE: _dl_catch_exception (dl-error-skeleton.c:196)
==958==    by 0x51A736E: _dl_catch_error (dl-error-skeleton.c:215)
==958==    by 0x4E3D734: _dlerror_run (dlerror.c:162)
==958==    by 0x4E3D050: dlopen@@GLIBC_2.2.5 (dlopen.c:87)
==958==    by 0x108769: main (mysql_dlopen.c:11)
==958== 
==958== LEAK SUMMARY:
==958==    definitely lost: 0 bytes in 0 blocks
==958==    indirectly lost: 0 bytes in 0 blocks
==958==      possibly lost: 0 bytes in 0 blocks
==958==    still reachable: 86,098 bytes in 27 blocks
==958==         suppressed: 0 bytes in 0 blocks
==958== 
==958== ERROR SUMMARY: 0 errors from 0 contexts (suppressed: 0 from 0)
==958== ERROR SUMMARY: 0 errors from 0 contexts (suppressed: 0 from 0)

Suggested fix:
 still reachable blocks should be 0
[11 Mar 2020 14:06] MySQL Verification Team
Hi Mr. Choudhary,

Thank you for your bug report.

However, I do not think that this is our bug.

You are not calling any of our functions from our C API. You are only calling a function from OS's system library.

Hence, it is not our bug.

Portions of this website are copyright © 2001, 2002 The PHP Group

Page generated in 0.053 sec. using MySQL 8.4.7-u6-cloud

Timestamp references displayed by the system are UTC.
Content reproduced on this site is the property of the respective copyright holders.
It is not reviewed in advance by Oracle and does not necessarily represent the opinion of Oracle or any other party.