Uploaded image for project: 'MariaDB Server'
  1. MariaDB Server
  2. MDEV-27627

LSAN: detected memory leaks - Memory not freed: 256/264/280/312 when using FOR...IN

Details

    Description

      FOR rec IN cur (2) DO SELECT * a;
      SHUTDOWN;
      

      2022-01-26 18:48:19 0 [Note] /test/MD190122-mariadb-10.8.0-linux-x86_64-dbg/bin/mysqld: Shutdown complete
       
      Warning: Memory not freed: 280
      Warning:  280 bytes lost at 0x15520001f630, allocated by T@0 at 0x55e20e710fe3, mysys/array.c:72, mysys/hash.c:98, sql/sp.cc:2330, sql/sp.cc:2645, sql/item_create.cc:2622, sql/item_create.cc:2471, sql/sql_yacc.yy:10468
      Memory lost: 280 bytes in 1 chunks
      Warning:  280 bytes lost at 0x15520001f630, allocated by T@0 at sql/sql_parse.cc:10379, mysys/array.c:72, mysys/hash.c:98, sql/sp.cc:2330, sql/sp.cc:2645, sql/item_create.cc:2622, sql/item_create.cc:2471, sql/sql_yacc.yy:10468
      Memory lost: 280 bytes in 1 chunks
      

      10.8.0 e222e44d1bfc995870430bb90d8ac97e91f66cb4 (Optimized)

      2022-01-26 18:52:17 0 [Note] /test/MD190122-mariadb-10.8.0-linux-x86_64-opt/bin/mysqld: Shutdown complete
       
      Warning: Memory not freed: 280
      

      10.3.33 97425f740faf83ac2d16585084476470f3f898ce (Optimized)

      2022-01-26 18:50:30 0 [Note] /test/MD190122-mariadb-10.3.33-linux-x86_64-opt/bin/mysqld: Shutdown complete
       
      Warning: Memory not freed: 264
      

      10.3.33 97425f740faf83ac2d16585084476470f3f898ce (Debug)

      2022-01-26 18:50:29 0 [Note] /test/MD190122-mariadb-10.3.33-linux-x86_64-dbg/bin/mysqld: Shutdown complete
       
      Warning: Memory not freed: 256
      Warning:  256 bytes lost at 0x14e3c4020020, allocated by T@0 at mysys/array.c:70, mysys/hash.c:98, sql/sp.cc:2290, sql/sp.cc:2605, sql/item_create.cc:3512, sql/item_create.cc:3361, sql/sql_yacc.yy:11201, sql/sql_parse.cc:10199
      Memory lost: 256 bytes in 1 chunks
      Warning:  256 bytes lost at 0x14e3c4020020, allocated by T@0 at mysys/array.c:70, mysys/hash.c:98, sql/sp.cc:2290, sql/sp.cc:2605, sql/item_create.cc:3512, sql/item_create.cc:3361, sql/sql_yacc.yy:11201, sql/sql_parse.cc:10199
      Memory lost: 256 bytes in 1 chunks
      

      Attachments

        Issue Links

          Activity

            Up to 10.11

            10.11.0 bc563f1a4b0b38de3b41fd0f0d3d8b7f1aacbd8b (Debug)

            2022-08-27 14:17:48 0 [Note] /test/MD190822-mariadb-10.11.0-linux-x86_64-dbg/bin/mysqld: Shutdown complete
             
            Warning: Memory not freed: 280
            Warning:  280 bytes lost at 0x1464f801f4a0, allocated by T@0 at 0x561d327d5c03, 0x561d327d9aec, 0x561d32264afa, 0x561d322653dd, mysys/array.c:72, mysys/hash.c:102, sql/sp.cc:2328, sql/sp.cc:2643
            Memory lost: 280 bytes in 1 chunks
            Warning:  280 bytes lost at 0x1464f801f4a0, allocated by T@0 at sql/item_create.cc:2719, sql/item_create.cc:2565, sql/sql_yacc.yy:10480, sql/sql_parse.cc:10426, mysys/array.c:72, mysys/hash.c:102, sql/sp.cc:2328, sql/sp.cc:2643
            Memory lost: 280 bytes in 1 chunks
            

            Roel Roel Van de Paar added a comment - Up to 10.11 10.11.0 bc563f1a4b0b38de3b41fd0f0d3d8b7f1aacbd8b (Debug) 2022-08-27 14:17:48 0 [Note] /test/MD190822-mariadb-10.11.0-linux-x86_64-dbg/bin/mysqld: Shutdown complete   Warning: Memory not freed: 280 Warning: 280 bytes lost at 0x1464f801f4a0, allocated by T@0 at 0x561d327d5c03, 0x561d327d9aec, 0x561d32264afa, 0x561d322653dd, mysys/array.c:72, mysys/hash.c:102, sql/sp.cc:2328, sql/sp.cc:2643 Memory lost: 280 bytes in 1 chunks Warning: 280 bytes lost at 0x1464f801f4a0, allocated by T@0 at sql/item_create.cc:2719, sql/item_create.cc:2565, sql/sql_yacc.yy:10480, sql/sql_parse.cc:10426, mysys/array.c:72, mysys/hash.c:102, sql/sp.cc:2328, sql/sp.cc:2643 Memory lost: 280 bytes in 1 chunks
            Roel Roel Van de Paar added a comment - - edited

            This testcase variation

            FOR rec IN cur (0) DO SELECT * cur;
            SET GLOBAL session_track_system_variables='a';
            SHUTDOWN;
            

            Leads to:

            Warning: Memory not freed: 312
            

            In all versions from 10.5 to 10.11, both debug and optimized. Possibly a split/additional issue.

            Roel Roel Van de Paar added a comment - - edited This testcase variation FOR rec IN cur (0) DO SELECT * cur; SET GLOBAL session_track_system_variables= 'a' ; SHUTDOWN; Leads to: Warning: Memory not freed: 312 In all versions from 10.5 to 10.11, both debug and optimized. Possibly a split/additional issue.
            Roel Roel Van de Paar added a comment - - edited

            LSAN is now picking this up as a memory leak:

            FOR rec IN cur (0) DO SELECT * cur;
            SHUTDOWN;
            

            CS 11.2.6 66b8d32b7514f46b1467d404d3f9ad688bbfeb4f (Debug, UBASAN)

            2024-11-01  8:40:33 0 [Note] /test/UBASAN_MD171024-mariadb-11.2.6-linux-x86_64-dbg/bin/mariadbd: Shutdown complete
             
            Warning: Memory not freed: 280
             
            =================================================================
            ==315613==ERROR: LeakSanitizer: detected memory leaks
             
            Direct leak of 280 byte(s) in 1 object(s) allocated from:
                #0 0x562787c25a67 in malloc (/test/UBASAN_MD171024-mariadb-11.2.6-linux-x86_64-dbg/bin/mariadbd+0x88b4a67)
                #1 0x56278ca90ca3 in my_malloc /test/11.2_dbg_san/mysys/my_malloc.c:93
                #2 0x56278ca1cca2 in init_dynamic_array2 /test/11.2_dbg_san/mysys/array.c:73
                #3 0x56278ca2d4c1 in my_hash_init2 /test/11.2_dbg_san/mysys/hash.c:99
                #4 0x56278ae66999 in sp_add_used_routine(Query_tables_list*, Query_arena*, MDL_key const*, Sp_handler const*, TABLE_LIST*) /test/11.2_dbg_san/sql/sp.cc:2387
                #5 0x56278ae6b0d1 in Sp_handler::add_used_routine(Query_tables_list*, Query_arena*, Database_qualified_name const*) const /test/11.2_dbg_san/sql/sp.cc:2701
                #6 0x56278a31850f in Create_sp_func::create_with_db(THD*, st_mysql_const_lex_string const*, st_mysql_const_lex_string const*, bool, List<Item>*) /test/11.2_dbg_san/sql/item_create.cc:2993
                #7 0x56278a2b4673 in Create_qfunc::create_func(THD*, st_mysql_const_lex_string const*, List<Item>*) /test/11.2_dbg_san/sql/item_create.cc:2840
                #8 0x5627899918fe in MYSQLparse(THD*) /test/11.2_dbg_san/sql/sql_yacc.yy:10594
                #9 0x5627885cbd38 in parse_sql(THD*, Parser_state*, Object_creation_ctx*, bool) /test/11.2_dbg_san/sql/sql_parse.cc:10329
                #10 0x5627885cd90f in mysql_parse(THD*, char*, unsigned int, Parser_state*) /test/11.2_dbg_san/sql/sql_parse.cc:7890
                #11 0x5627885de29b in dispatch_command(enum_server_command, THD*, char*, unsigned int, bool) /test/11.2_dbg_san/sql/sql_parse.cc:1894
                #12 0x5627885ecb06 in do_command(THD*, bool) /test/11.2_dbg_san/sql/sql_parse.cc:1407
                #13 0x562789014791 in do_handle_one_connection(CONNECT*, bool) /test/11.2_dbg_san/sql/sql_connect.cc:1439
                #14 0x562789015cb3 in handle_one_connection /test/11.2_dbg_san/sql/sql_connect.cc:1341
                #15 0x14ca3389ca93 in start_thread nptl/pthread_create.c:447
            

            And running this accross versions produces multiple stacks (one per line):

            LSAN|memory leak|mysys/my_malloc.c|__interceptor_malloc|my_malloc|init_dynamic_array2|my_hash_init2
            LSAN|memory leak|mysys/my_malloc.c|malloc|my_malloc|init_dynamic_array2|my_hash_init2
            LSAN|memory leak|mysys/my_malloc.c|malloc|my_malloc|init_dynamic_array2|sp_add_used_routine
            

            The last one is interesting as it is the same stack as seen in MDEV-34405

            Roel Roel Van de Paar added a comment - - edited LSAN is now picking this up as a memory leak: FOR rec IN cur (0) DO SELECT * cur; SHUTDOWN; CS 11.2.6 66b8d32b7514f46b1467d404d3f9ad688bbfeb4f (Debug, UBASAN) 2024-11-01 8:40:33 0 [Note] /test/UBASAN_MD171024-mariadb-11.2.6-linux-x86_64-dbg/bin/mariadbd: Shutdown complete   Warning: Memory not freed: 280   ================================================================= ==315613==ERROR: LeakSanitizer: detected memory leaks   Direct leak of 280 byte(s) in 1 object(s) allocated from: #0 0x562787c25a67 in malloc (/test/UBASAN_MD171024-mariadb-11.2.6-linux-x86_64-dbg/bin/mariadbd+0x88b4a67) #1 0x56278ca90ca3 in my_malloc /test/11.2_dbg_san/mysys/my_malloc.c:93 #2 0x56278ca1cca2 in init_dynamic_array2 /test/11.2_dbg_san/mysys/array.c:73 #3 0x56278ca2d4c1 in my_hash_init2 /test/11.2_dbg_san/mysys/hash.c:99 #4 0x56278ae66999 in sp_add_used_routine(Query_tables_list*, Query_arena*, MDL_key const*, Sp_handler const*, TABLE_LIST*) /test/11.2_dbg_san/sql/sp.cc:2387 #5 0x56278ae6b0d1 in Sp_handler::add_used_routine(Query_tables_list*, Query_arena*, Database_qualified_name const*) const /test/11.2_dbg_san/sql/sp.cc:2701 #6 0x56278a31850f in Create_sp_func::create_with_db(THD*, st_mysql_const_lex_string const*, st_mysql_const_lex_string const*, bool, List<Item>*) /test/11.2_dbg_san/sql/item_create.cc:2993 #7 0x56278a2b4673 in Create_qfunc::create_func(THD*, st_mysql_const_lex_string const*, List<Item>*) /test/11.2_dbg_san/sql/item_create.cc:2840 #8 0x5627899918fe in MYSQLparse(THD*) /test/11.2_dbg_san/sql/sql_yacc.yy:10594 #9 0x5627885cbd38 in parse_sql(THD*, Parser_state*, Object_creation_ctx*, bool) /test/11.2_dbg_san/sql/sql_parse.cc:10329 #10 0x5627885cd90f in mysql_parse(THD*, char*, unsigned int, Parser_state*) /test/11.2_dbg_san/sql/sql_parse.cc:7890 #11 0x5627885de29b in dispatch_command(enum_server_command, THD*, char*, unsigned int, bool) /test/11.2_dbg_san/sql/sql_parse.cc:1894 #12 0x5627885ecb06 in do_command(THD*, bool) /test/11.2_dbg_san/sql/sql_parse.cc:1407 #13 0x562789014791 in do_handle_one_connection(CONNECT*, bool) /test/11.2_dbg_san/sql/sql_connect.cc:1439 #14 0x562789015cb3 in handle_one_connection /test/11.2_dbg_san/sql/sql_connect.cc:1341 #15 0x14ca3389ca93 in start_thread nptl/pthread_create.c:447 And running this accross versions produces multiple stacks (one per line): LSAN|memory leak|mysys/my_malloc.c|__interceptor_malloc|my_malloc|init_dynamic_array2|my_hash_init2 LSAN|memory leak|mysys/my_malloc.c|malloc|my_malloc|init_dynamic_array2|my_hash_init2 LSAN|memory leak|mysys/my_malloc.c|malloc|my_malloc|init_dynamic_array2|sp_add_used_routine The last one is interesting as it is the same stack as seen in MDEV-34405

            People

              shulga Dmitry Shulga
              Roel Roel Van de Paar
              Votes:
              0 Vote for this issue
              Watchers:
              4 Start watching this issue

              Dates

                Created:
                Updated:

                Git Integration

                  Error rendering 'com.xiplink.jira.git.jira_git_plugin:git-issue-webpanel'. Please contact your Jira administrators.