Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix memory leaks detected during testing #3620

Closed
4 tasks done
JavierJF opened this issue Sep 10, 2021 · 0 comments · Fixed by #3621
Closed
4 tasks done

Fix memory leaks detected during testing #3620

JavierJF opened this issue Sep 10, 2021 · 0 comments · Fixed by #3621
Assignees
Labels

Comments

@JavierJF
Copy link
Collaborator

  • A clear description of the issue

The following two memory leaks have been detected during testing:

First leak

Leak is directly tied to handler___status_CONNECTING_CLIENT___STATE_SERVER_HANDSHAKE,
related to memory allocated to client_addr. As we can see by the log:

2021-09-10 16:13:55 MySQL_Session.cpp:5098:handler___status_CONNECTING_CLIENT___STATE_SERVER_HANDSHAKE(): [ERROR] ProxySQL Error: Access denied for user 'inv_user'@'10.200.1.2' (using password: YES)
2021-09-10 16:13:56 MySQL_Session.cpp:5098:handler___status_CONNECTING_CLIENT___STATE_SERVER_HANDSHAKE(): [ERROR] ProxySQL Error: Access denied for user 'inv_user'@'10.200.1.2' (using password: YES)
2021-09-10 16:13:56 MySQL_Session.cpp:5098:handler___status_CONNECTING_CLIENT___STATE_SERVER_HANDSHAKE(): [ERROR] ProxySQL Error: Access denied for user 'inv_user'@'10.200.1.2' (using password: YES)
2021-09-10 16:13:57 MySQL_Session.cpp:5098:handler___status_CONNECTING_CLIENT___STATE_SERVER_HANDSHAKE(): [ERROR] ProxySQL Error: Access denied for user 'inv_user'@'10.200.1.2' (using password: YES)
==1202933==ERROR: LeakSanitizer: detected memory leaks

Direct leak of 44 byte(s) in 4 object(s) allocated from:
    #0 0x7f1340b783f9 in __interceptor_strdup /build/gcc/src/gcc/libsanitizer/asan/asan_interceptors.cpp:454
    #1 0x565348b76756 in MySQL_Session::handler___status_CONNECTING_CLIENT___STATE_SERVER_HANDSHAKE(_PtrSize_t*, bool*) /home/javjarfer/Projects/proxysql_v2.X.0/lib/MySQL_Session.cpp:5059
    #2 0x565348b61e4a in MySQL_Session::get_pkts_from_client(bool&, _PtrSize_t&) /home/javjarfer/Projects/proxysql_v2.X.0/lib/MySQL_Session.cpp:3416
    #3 0x565348b6bdd1 in MySQL_Session::handler() /home/javjarfer/Projects/proxysql_v2.X.0/lib/MySQL_Session.cpp:4254
    #4 0x565348aeb2a0 in MySQL_Thread::process_all_sessions() /home/javjarfer/Projects/proxysql_v2.X.0/lib/MySQL_Thread.cpp:3539
    #5 0x565348ae51a3 in MySQL_Thread::run() /home/javjarfer/Projects/proxysql_v2.X.0/lib/MySQL_Thread.cpp:3051
    #6 0x565348902f6e in mysql_worker_thread_func(void*) /home/javjarfer/Projects/proxysql_v2.X.0/src/main.cpp:417
    #7 0x7f1340903258 in start_thread (/usr/lib/libpthread.so.0+0x9258)

Direct leak of 36 byte(s) in 1 object(s) allocated from:
    #0 0x7f1340bd3279 in __interceptor_malloc /build/gcc/src/gcc/libsanitizer/asan/asan_malloc_linux.cpp:145
    #1 0x565348aaf5d4 in MySQL_Data_Stream::buffer2array() /home/javjarfer/Projects/proxysql_v2.X.0/lib/mysql_data_stream.cpp:975
    #2 0x565348aad8ff in MySQL_Data_Stream::read_pkts() /home/javjarfer/Projects/proxysql_v2.X.0/lib/mysql_data_stream.cpp:892
    #3 0x565348c36fd5 in child_mysql(void*) /home/javjarfer/Projects/proxysql_v2.X.0/lib/ProxySQL_Admin.cpp:4908
    #4 0x7f1340903258 in start_thread (/usr/lib/libpthread.so.0+0x9258)

Leak is related with failed connections. Same result isn't achieved for non-failing
connections.

Second leak

Leak is related with SSL connections:

==1199044==ERROR: LeakSanitizer: detected memory leaks

Direct leak of 252 byte(s) in 7 object(s) allocated from:
    #0 0x7f3fb412b279 in __interceptor_malloc /build/gcc/src/gcc/libsanitizer/asan/asan_malloc_linux.cpp:145
    #1 0x5612e29f05d4 in MySQL_Data_Stream::buffer2array() /home/javjarfer/Projects/proxysql_v2.X.0/lib/mysql_data_stream.cpp:975
    #2 0x5612e29ee8ff in MySQL_Data_Stream::read_pkts() /home/javjarfer/Projects/proxysql_v2.X.0/lib/mysql_data_stream.cpp:892
    #3 0x5612e2a28fa7 in MySQL_Thread::process_data_on_data_stream(MySQL_Data_Stream*, unsigned int) /home/javjarfer/Projects/proxysql_v2.X.0/lib/MySQL_Thread.cpp:3277
    #4 0x5612e2a23dd0 in MySQL_Thread::ProcessAllMyDS_AfterPoll() /home/javjarfer/Projects/proxysql_v2.X.0/lib/MySQL_Thread.cpp:2793
    #5 0x5612e2a25f8d in MySQL_Thread::run() /home/javjarfer/Projects/proxysql_v2.X.0/lib/MySQL_Thread.cpp:3035
    #6 0x5612e2843f6e in mysql_worker_thread_func(void*) /home/javjarfer/Projects/proxysql_v2.X.0/src/main.cpp:417
    #7 0x7f3fb3e5b258 in start_thread (/usr/lib/libpthread.so.0+0x9258)

Direct leak of 36 byte(s) in 1 object(s) allocated from:
    #0 0x7f3fb412b279 in __interceptor_malloc /build/gcc/src/gcc/libsanitizer/asan/asan_malloc_linux.cpp:145
    #1 0x5612e29f05d4 in MySQL_Data_Stream::buffer2array() /home/javjarfer/Projects/proxysql_v2.X.0/lib/mysql_data_stream.cpp:975
    #2 0x5612e29ee8ff in MySQL_Data_Stream::read_pkts() /home/javjarfer/Projects/proxysql_v2.X.0/lib/mysql_data_stream.cpp:892
    #3 0x5612e2b77fd5 in child_mysql(void*) /home/javjarfer/Projects/proxysql_v2.X.0/lib/ProxySQL_Admin.cpp:4908
    #4 0x7f3fb3e5b258 in start_thread (/usr/lib/libpthread.so.0+0x9258)
  • ProxySQL version

v2.x

  • OS version
NAME="Arch Linux"
PRETTY_NAME="Arch Linux"
ID=arch
BUILD_ID=rolling
  • The steps to reproduce the issue

The provided script should be enough to reproduce both issues, sanitizer output should be:

Direct leak of 108 byte(s) in 3 object(s) allocated from:
    #0 0x7f1985b0d279 in __interceptor_malloc /build/gcc/src/gcc/libsanitizer/asan/asan_malloc_linux.cpp:145
    #1 0x56403038a5d4 in MySQL_Data_Stream::buffer2array() /home/javjarfer/Projects/proxysql_v2.X.0/lib/mysql_data_stream.cpp:975
    #2 0x5640303888ff in MySQL_Data_Stream::read_pkts() /home/javjarfer/Projects/proxysql_v2.X.0/lib/mysql_data_stream.cpp:892
    #3 0x5640303c2fa7 in MySQL_Thread::process_data_on_data_stream(MySQL_Data_Stream*, unsigned int) /home/javjarfer/Projects/proxysql_v2.X.0/lib/MySQL_Thread.cpp:3277
    #4 0x5640303bddd0 in MySQL_Thread::ProcessAllMyDS_AfterPoll() /home/javjarfer/Projects/proxysql_v2.X.0/lib/MySQL_Thread.cpp:2793
    #5 0x5640303bff8d in MySQL_Thread::run() /home/javjarfer/Projects/proxysql_v2.X.0/lib/MySQL_Thread.cpp:3035
    #6 0x5640301ddf6e in mysql_worker_thread_func(void*) /home/javjarfer/Projects/proxysql_v2.X.0/src/main.cpp:417
    #7 0x7f198583d258 in start_thread (/usr/lib/libpthread.so.0+0x9258)

Direct leak of 108 byte(s) in 3 object(s) allocated from:
    #0 0x7f1985b0d279 in __interceptor_malloc /build/gcc/src/gcc/libsanitizer/asan/asan_malloc_linux.cpp:145
    #1 0x56403038a5d4 in MySQL_Data_Stream::buffer2array() /home/javjarfer/Projects/proxysql_v2.X.0/lib/mysql_data_stream.cpp:975
    #2 0x5640303888ff in MySQL_Data_Stream::read_pkts() /home/javjarfer/Projects/proxysql_v2.X.0/lib/mysql_data_stream.cpp:892
    #3 0x564030511fd5 in child_mysql(void*) /home/javjarfer/Projects/proxysql_v2.X.0/lib/ProxySQL_Admin.cpp:4908
    #4 0x7f198583d258 in start_thread (/usr/lib/libpthread.so.0+0x9258)

Direct leak of 33 byte(s) in 3 object(s) allocated from:
    #0 0x7f1985ab23f9 in __interceptor_strdup /build/gcc/src/gcc/libsanitizer/asan/asan_interceptors.cpp:454
    #1 0x564030451756 in MySQL_Session::handler___status_CONNECTING_CLIENT___STATE_SERVER_HANDSHAKE(_PtrSize_t*, bool*) /home/javjarfer/Projects/proxysql_v2.X.0/lib/MySQL_Session.cpp:5059
    #2 0x56403043ce4a in MySQL_Session::get_pkts_from_client(bool&, _PtrSize_t&) /home/javjarfer/Projects/proxysql_v2.X.0/lib/MySQL_Session.cpp:3416
    #3 0x564030446dd1 in MySQL_Session::handler() /home/javjarfer/Projects/proxysql_v2.X.0/lib/MySQL_Session.cpp:4254
    #4 0x5640303c62a0 in MySQL_Thread::process_all_sessions() /home/javjarfer/Projects/proxysql_v2.X.0/lib/MySQL_Thread.cpp:3539
    #5 0x5640303c01a3 in MySQL_Thread::run() /home/javjarfer/Projects/proxysql_v2.X.0/lib/MySQL_Thread.cpp:3051
    #6 0x5640301ddf6e in mysql_worker_thread_func(void*) /home/javjarfer/Projects/proxysql_v2.X.0/src/main.cpp:417
    #7 0x7f198583d258 in start_thread (/usr/lib/libpthread.so.0+0x9258)

Script:
reproduce_leaks.sh.tar.gz

@JavierJF JavierJF self-assigned this Sep 10, 2021
@JavierJF JavierJF added the bug label Sep 10, 2021
JavierJF added a commit that referenced this issue Sep 10, 2021
JavierJF added a commit that referenced this issue Sep 14, 2021
Fixes memory leaks detected during testing - Closes #3620
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant