[MDEV-26463] Memory leak in embedded server bootstrap Created: 2021-08-23  Updated: 2023-12-19

Status: Open
Project: MariaDB Server
Component/s: Embedded Server
Affects Version/s: 10.2, 10.3, 10.4, 10.5, 10.6, 10.7
Fix Version/s: None

Type: Bug Priority: Major
Reporter: Marko Mäkelä Assignee: Unassigned
Resolution: Unresolved Votes: 0
Labels: ASAN, leak

Issue Links:
Relates
relates to MDEV-12749 multiple tests fail in buildbot with ... Stalled

 Description   

A memory leak on the embedded server bootstrap makes ./mtr --embedded almost useless for AddressSanitizer runs:

mkdir bld
cd bld
cmake -DWITH_EMBEDDED_SERVER=ON -DWITH_ASAN=ON ..
cmake --build .
(cd mysql-test; ASAN_OPTIONS=log_path=/dev/shm/10.2-embedded:fast_unwind_on_malloc=0 ./mtr --embedded --parallel=auto)

Note: When the code is compiled with GCC, many tests will pass despite leaks. When compiled with Clang, tests will fail more easily.
Here is the contents of a sample file /dev/shm/10.2-embedded.*:

10.2 ca89489716890ebab5b207e49f3b157e78e0f8e4

 
=================================================================
==4111278==ERROR: LeakSanitizer: detected memory leaks
 
Direct leak of 16400 byte(s) in 1 object(s) allocated from:
    #0 0x7f8decc8c7cf in __interceptor_malloc ../../../../src/libsanitizer/asan/asan_malloc_linux.cpp:145
    #1 0x55c0ed114981 in my_malloc /mariadb/10.2o/mysys/my_malloc.c:101
    #2 0x55c0ed1b23c2 in net_allocate_new_packet(st_net*, void*, unsigned int) /mariadb/10.2o/sql/net_serv.cc:177
    #3 0x55c0ed1b24be in my_net_init /mariadb/10.2o/sql/net_serv.cc:141
    #4 0x55c0ed13f261 in bootstrap /mariadb/10.2o/libmysqld/../sql/mysqld.cc:6469
    #5 0x55c0ed13f261 in read_init_file /mariadb/10.2o/libmysqld/../sql/mysqld.cc:6509
    #6 0x55c0ed13f261 in init_embedded_server /mariadb/10.2o/libmysqld/lib_sql.cc:636
    #7 0x55c0ed074138 in main /mariadb/10.2o/client/mysqltest.cc:9202
    #8 0x7f8dec1ead09 in __libc_start_main ../csu/libc-start.c:308
    #9 0x55c0ed0adba9 in _start (/dev/shm/10.2o/libmysqld/examples/mysqltest_embedded+0x79cba9)
 
SUMMARY: AddressSanitizer: 16400 byte(s) leaked in 1 allocation(s).

Similar leaks are reported for 10.5 and 10.6 as well.

Furthermore, the ./mtr --embedded run of a 10.6 GCC ASAN build would seemingly hang using 100% CPU; sudo perf top -g would attribute 95% of all samples to __asan::AsanDie(). This would happen after only 2 reported test failures, after 4197 tests, 1167 to go. I suspect that it could be related to the bootstrap leak.



 Comments   
Comment by Eric Xu [ 2022-01-10 ]

Hi, guys, Is there any progress on resolving this issue ?

Comment by Sergei Golubchik [ 2022-01-10 ]

Not yet. Why, is it an important issue for you?

Comment by Eric Xu [ 2022-01-20 ]

Hi, Sergei, I'm using mariadb as an embedded database within a http server. For each natural language query received, we parse and create corresponding sql query. Now I found the embedded database might have memory leak issue. The issue could be detected by valgrind

Comment by Sergei Golubchik [ 2022-03-10 ]

axu123, this leak is a memory allocated on library load and not freed — at least that's what it looks like from the stack trace. It will only be a concern for you if your application (http server or php or whatever) constantly loads and unloads libmysqld.so. So I expect it should not be an issue for you. It's practically a problem only for us as it produces annoying errors in the test suite.

Generated at Thu Feb 08 09:45:30 UTC 2024 using Jira 8.20.16#820016-sha1:9d11dbea5f4be3d4cc21f03a88dd11d8c8687422.