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

SQL service leaks the results of a query that fails after sending rows, and of a connection closed with results not read

    XMLWordPrintable

Details

    • Bug
    • Status: Open (View Workflow)
    • Major
    • Resolution: Unresolved
    • 13.1.1
    • None
    • Plugins
    • None

    Description

      Two memory leaks in the SQL service for plugins (mysql_real_connect_local(), MDEV-19275). Both are visible in a debug build as lost bytes reported by safemalloc at shutdown.

      1. Rows of a query that fails after sending some are not freed

      A query that a plugin runs through the SQL service can fail after it has sent its metadata or some rows. Examples:

      • a subquery that returns more than one row on a later row
      • a KILL QUERY between rows

      In that case the fields and rows already read stay allocated until shutdown. loc_read_rows() reports the error through embedded_get_error(), which frees the dataset but not the memory root that holds its fields and rows.

      How to repeat:

      install plugin test_sql_service soname 'test_sql_service';
      create table t1 (a int);
      insert into t1 values (1), (2);
      set global test_sql_service_execute_sql_local=
        'select if(a = 2, (select 1 union all select 2), a) from test.t1 order by a';
      set global test_sql_service_execute_sql_global=
        'select if(a = 2, (select 1 union all select 2), a) from test.t1 order by a';
      drop table t1;
      uninstall plugin test_sql_service;
      

      Result: at shutdown a debug build reports the lost bytes.

      2. Closing a connection leaks the results it did not read

      A SQL service connection keeps the results of a statement in a list of Protocol_local. The next command on the connection frees them. Closing the connection frees the Protocol_local but not those results.

      After a CALL whose rows were read, the OK packet that ends the CALL is never read, so it leaks: 728 bytes per connection.

      How to repeat:

      install plugin test_sql_service soname 'test_sql_service';
      create procedure test.p() select 1 as a union all select 2;
      set global test_sql_service_execute_sql_local= 'call test.p()';
      set global test_sql_service_execute_sql_global= 'call test.p()';
      drop procedure test.p;
      uninstall plugin test_sql_service;
      

      Result: at shutdown a debug build reports the lost bytes.

      Attachments

        Activity

          People

            rennox Juan René Ramírez Monarrez
            rennox Juan René Ramírez Monarrez
            Votes:
            0 Vote for this issue
            Watchers:
            1 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.