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

LeakSanitizer: detected memory leaks on PREPARE with WITH RECURSIVE

    XMLWordPrintable

Details

    Description

      CREATE TABLE t (a INT,b TEXT);
      --ERROR ER_WRONG_NUMBER_OF_COLUMNS_IN_SELECT
      PREPARE s FROM 'WITH RECURSIVE d AS (SELECT * FROM t UNION ALL SELECT 1 FROM d) SELECT * FROM d AS d1,d AS d2';
      SHUTDOWN;
      

      Leads to:

      CS 12.1.0 247e2f8d4dd4124356a337f6b903b176c6780440 (Optimized, UBASAN, Clang) Build 16/06/2025

      2025-06-27  9:16:10 0 [Note] /test/UBASAN_MD160625-mariadb-12.1.0-linux-x86_64-opt/bin/mariadbd: Shutdown complete
      Warning: Internal memory accounting error of 144 bytes
       
      =================================================================
      ==1298998==ERROR: LeakSanitizer: detected memory leaks
       
      Direct leak of 32760 byte(s) in 1 object(s) allocated from:
          #0 0x560f9270b323 in malloc (/test/UBASAN_MD160625-mariadb-12.1.0-linux-x86_64-opt/bin/mariadbd+0x1ef2323) (BuildId: 83676445a118718883344a6b9450d04346216a3e)
          #1 0x560f951f5542 in my_malloc /test/12.1_opt_san/mysys/my_malloc.c:93:29
          #2 0x560f951d01ec in root_alloc /test/12.1_opt_san/mysys/my_alloc.c:66:10
          #3 0x560f951d01ec in init_alloc_root /test/12.1_opt_san/mysys/my_alloc.c:178:22
          #4 0x560f932a57e9 in init_sql_alloc(unsigned int, st_mem_root*, unsigned int, unsigned int, unsigned long) /test/12.1_opt_san/sql/thr_malloc.cc:64:3
          #5 0x560f92f39b19 in Create_tmp_table::start(THD*, TMP_TABLE_PARAM*, st_mysql_const_lex_string const*) /test/12.1_opt_san/sql/sql_select.cc:22033:3
          #6 0x560f92eace11 in create_tmp_table(THD*, TMP_TABLE_PARAM*, List<Item>&, st_order*, bool, bool, unsigned long long, unsigned long long, st_mysql_const_lex_string const*, bool, bool) /test/12.1_opt_san/sql/
      sql_select.cc:22901:22
          #7 0x560f93197ab4 in select_unit::create_result_table(THD*, List<Item>*, bool, unsigned long long, st_mysql_const_lex_string const*, bool, bool, bool, unsigned int) /test/12.1_opt_san/sql/sql_union.cc:355:17
          #8 0x560f9318a5d8 in st_select_lex_unit::prepare(TABLE_LIST*, select_result*, unsigned long long) /test/12.1_opt_san/sql/sql_union.cc:1756:45
          #9 0x560f92b5715f in mysql_derived_prepare(THD*, LEX*, TABLE_LIST*) /test/12.1_opt_san/sql/sql_derived.cc:840:19
          #10 0x560f92b60b3c in mysql_handle_single_derived(LEX*, TABLE_LIST*, unsigned int) /test/12.1_opt_san/sql/sql_derived.cc:200:15
          #11 0x560f9328f78e in TABLE_LIST::handle_derived(LEX*, unsigned int) /test/12.1_opt_san/sql/table.cc:9962:9
          #12 0x560f92c1f3da in LEX::handle_list_of_derived(TABLE_LIST*, unsigned int) /test/12.1_opt_san/sql/sql_lex.h:4652:43
          #13 0x560f92c1f3da in st_select_lex::handle_derived(LEX*, unsigned int) /test/12.1_opt_san/sql/sql_lex.cc:5146:15
          #14 0x560f92b56cb0 in mysql_derived_prepare(THD*, LEX*, TABLE_LIST*) /test/12.1_opt_san/sql/sql_derived.cc:794:21
          #15 0x560f92b600a6 in mysql_handle_derived(LEX*, unsigned int) /test/12.1_opt_san/sql/sql_derived.cc:123:7
          #16 0x560f92a407fb in open_normal_and_derived_tables(THD*, TABLE_LIST*, unsigned int, unsigned int) /test/12.1_opt_san/sql/sql_base.cc:5773:7
          #17 0x560f92de0c24 in mysql_test_select(Prepared_statement*, TABLE_LIST*) /test/12.1_opt_san/sql/sql_prepare.cc:1484:7
          #18 0x560f92de0c24 in check_prepared_statement(Prepared_statement*) /test/12.1_opt_san/sql/sql_prepare.cc:2316:10
          #19 0x560f92dc5e2a in Prepared_statement::prepare(char const*, unsigned int) /test/12.1_opt_san/sql/sql_prepare.cc:4233:12
          #20 0x560f92dc9ace in mysql_sql_stmt_prepare(THD*) /test/12.1_opt_san/sql/sql_prepare.cc:2805:19
          #21 0x560f92d1002f in mysql_execute_command(THD*, bool) /test/12.1_opt_san/sql/sql_parse.cc:3965:5
          #22 0x560f92ceaa90 in mysql_parse(THD*, char*, unsigned int, Parser_state*) /test/12.1_opt_san/sql/sql_parse.cc:7882:18
          #23 0x560f92ce1de6 in dispatch_command(enum_server_command, THD*, char*, unsigned int, bool) /test/12.1_opt_san/sql/sql_parse.cc:1877:7
          #24 0x560f92cecd56 in do_command(THD*, bool) /test/12.1_opt_san/sql/sql_parse.cc:1416:17
          #25 0x560f9337ac5c in do_handle_one_connection(CONNECT*, bool) /test/12.1_opt_san/sql/sql_connect.cc:1414:11
          #26 0x560f9337a4b6 in handle_one_connection /test/12.1_opt_san/sql/sql_connect.cc:1326:5
          #27 0x560f92708e0c in asan_thread_start(void*) asan_interceptors.cpp.o
          [..]
      SUMMARY: AddressSanitizer: 119592 byte(s) leaked in 9 allocation(s).
      

      Setup:

      Compiled with a recent version of Clang (I used Clang 18.1.3) with LLVM 18. Ubuntu instructions:
        # Note: It is strongly recommended to uninstall all old Clang & LLVM packages (ref  dpkg --list | grep -iE 'clang|llvm'  and use  apt purge  and  dpkg --purge  to remove the packages), before installing Clang/LLVM 18
           sudo apt install clang llvm-18 llvm-18-linker-tools llvm-18-runtime llvm-18-tools llvm-18-dev libstdc++-14-dev llvm-dev
      Compiled with: "-DCMAKE_C_COMPILER=/usr/bin/clang -DCMAKE_CXX_COMPILER=/usr/bin/clang++ -DCMAKE_C{,XX}_FLAGS='-march=native -mtune=native'" and:
          -DWITH_ASAN=ON -DWITH_ASAN_SCOPE=ON -DWITH_UBSAN=ON -DWSREP_LIB_WITH_ASAN=ON
      Set before execution:
          export UBSAN_OPTIONS=print_stacktrace=1:report_error_type=1   # And you may also want to supress UBSAN startup issues using 'suppressions=UBSAN.filter' in UBSAN_OPTIONS. For an example of UBSAN.filter, which includes current startup issues see: https://github.com/mariadb-corporation/mariadb-qa/blob/master/UBSAN.filter
          export ASAN_OPTIONS=quarantine_size_mb=512:atexit=0:detect_invalid_pointer_pairs=3:dump_instruction_bytes=1:abort_on_error=1:allocator_may_return_null=1
      

      SAN Bug Detection Matrix

          Rel    o/d  Build   Commit                                    UniqueID observed             
      CS  10.6   dbg  150525  60f046d7e6b0a61f9b0762fe05c4021cff1b79d8  No bug found                  
      CS  10.6   opt  150525  60f046d7e6b0a61f9b0762fe05c4021cff1b79d8  MEMORY_NOT_FREED|Warning: Memory not freed
      CS  10.11  dbg  170625  629b8d782cd20194cc1181451306321e44d2ae02  No bug found                  
      CS  10.11  opt  170625  629b8d782cd20194cc1181451306321e44d2ae02  MEMORY_NOT_FREED|Warning: Memory not freed
      CS  11.4   dbg  150525  da5a4d05b9da58705498a42b6ffa5d9211f446af  No bug found                  
      CS  11.4   opt  150525  da5a4d05b9da58705498a42b6ffa5d9211f446af  LSAN|memory leak|mysys/my_malloc.c|malloc|my_malloc|root_alloc|init_alloc_root
      CS  11.8   dbg  150525  865b05bf4acf10e0d4b3359019ed7b2efe0be81d  No bug found                  
      CS  11.8   opt  150525  865b05bf4acf10e0d4b3359019ed7b2efe0be81d  LSAN|memory leak|mysys/my_malloc.c|malloc|my_malloc|root_alloc|init_alloc_root                  
      CS  12.0   dbg  140525  00a9afb5818433c26537ccaf6b2c59ad493dd473  No bug found                  
      CS  12.0   opt  140525  00a9afb5818433c26537ccaf6b2c59ad493dd473  LSAN|memory leak|mysys/my_malloc.c|malloc|my_malloc|root_alloc|init_alloc_root                  
      CS  12.1   dbg  160625  247e2f8d4dd4124356a337f6b903b176c6780440  No bug found                  
      CS  12.1   opt  160625  247e2f8d4dd4124356a337f6b903b176c6780440  LSAN|memory leak|mysys/my_malloc.c|malloc|my_malloc|root_alloc|init_alloc_root
      ES  10.6   opt  150525  6111fbaf7bdcb6f1170f556ffd05d6e1a4159f62  MEMORY_NOT_FREED|Warning: Memory not freed
      ES  11.4   dbg  150525  9cd12544ebfd0d52d2158af66b5aced58121cf1f  No bug found                  
      ES  11.4   opt  150525  9cd12544ebfd0d52d2158af66b5aced58121cf1f  LSAN|memory leak|mysys/my_malloc.c|malloc|my_malloc|root_alloc|init_alloc_root
      

      Attachments

        Activity

          People

            shulga Dmitry Shulga
            ramesh Ramesh Sivaraman
            Votes:
            0 Vote for this issue
            Watchers:
            3 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.