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

Memory leak on re-compilation of a failing statement inside a stored routine

    XMLWordPrintable

Details

    Description

      Consider the following use case:

      CREATE TABLE t1 (a INT);
      CREATE PROCEDURE p1()
      SELECT * FROM t1;
      CALL p1();
      DROP TABLE t1;
      CREATE TABLE t1 (a INT);
      CALL p1(); # <<=== Second call of the stored procedure p1 could lead to memory leaks
      

      Memory leaks is caused by re-parsing of the failed statement (SELECT * FROM t1 in the mentioned case). On re-parsing, a memory is allocated on sp_head memory root that was already marked as read-only after first success execution of the stored procedure p1.

      This issue is fixed by adding a new memory root to SP-instruction on starting re-parsing process and forwarding further memory allocations that will taken place on re-parsing of a SP instruction's statement to this new memory root. Please draw attention, that a memory for the new mem_root is allocated on sp_head's memory root and pointer to the new memory root is stored inside the SP-instruction class sp_lex_instr.

      Attachments

        Issue Links

          Activity

            People

              shulga Dmitry Shulga
              shulga Dmitry Shulga
              Votes:
              0 Vote for this issue
              Watchers:
              2 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved:

                Git Integration

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