Bug #56652 Valgrind warnings for memory leak in ALTER TABLE and/or plugin/semisync
Submitted: 8 Sep 2010 13:56 Modified: 10 Nov 2011 19:00
Reporter: Sven Sandberg Email Updates:
Status: Closed Impact on me:
None 
Category:MySQL Server: DDL Severity:S2 (Serious)
Version:trunk, 5.6 OS:Any
Assigned to: Mats Kindahl
Tags: ALTER TABLE, memory leak, plugin, semisync, valgrind
Triage: Triaged: D1 (Critical)

[8 Sep 2010 13:56] Sven Sandberg
Description:
This is one of several Valgrind warnings for trunk-bugfixing in pb2 at https://central.sun.net/http://pb2.norway.sun.com/?action=archive_download&archive_id=2239... . After running tests related to semisync plugin, it says this:

worker[1] Valgrind report from /export/home2/pb2/test/sb_0-2236760-1283495420.63/mysql-5.6.1-m4-linux-x86_64-test/mysql-test/var-n_mix/1/log/mysqld.1.err after tests: sys_vars.rpl_semi_sync_master_enabled_basic sys_vars.rpl_semi_sync_master_trace_level_basic sys_vars.rpl_semi_sync_master_wait_no_slave_basic sys_vars.rpl_semi_sync_slave_enabled_basic sys_vars.rpl_semi_sync_slave_trace_level_basic main.fulltext_plugin
------------------------------------------------------------
ERROR SUMMARY: 0 errors from 0 contexts (suppressed: 23 from 1)
malloc/free: in use at exit: 2,114 bytes in 18 blocks.
malloc/free: 91,751 allocs, 91,733 frees, 493,304,968 bytes allocated.
For counts of detected errors, rerun with: -v
searching for pointers to 18 not-freed blocks.
checked 4,287,984 bytes.

26 bytes in 1 blocks are definitely lost in loss record 3 of 8
   at 0x4A05809: malloc (vg_replace_malloc.c:149)
   by 0xA72A64: my_malloc (my_malloc.c:38)
   by 0xA72DFE: my_strdup (my_malloc.c:146)
   by 0x5CB539: intern_sys_var_ptr(THD*, int, bool) (sql_plugin.cc:2500)
   by 0x5CB68F: mysql_sys_var_long(THD*, int) (sql_plugin.cc:2540)
   by 0x8C3D67: ha_myisam::enable_indexes(unsigned) (ha_myisam.cc:1345)
   by 0x8C0DC6: ha_myisam::end_bulk_insert() (ha_myisam.cc:1485)
   by 0x5AA503: handler::ha_end_bulk_insert() (handler.h:1345)
   by 0x62EA13: copy_data_between_tables(TABLE*, TABLE*, List<Create_field>&, bool, unsigned, st_order*, unsigned long long*, unsigned long long*, enum_enable_or_disable, bool) (sql_table.cc:7160)
   by 0x63BE99: mysql_alter_table(THD*, char*, char*, st_ha_create_information*, TABLE_LIST*, Alter_info*, unsigned, st_order*, bool) (sql_table.cc:6528)
   by 0x830034: Alter_table_statement::execute(THD*) (sql_alter.cc:104)
   by 0x5C1FC4: mysql_execute_command(THD*) (sql_parse.cc:4407)
   by 0x5C2581: mysql_parse(THD*, char*, unsigned, Parser_state*) (sql_parse.cc:5586)
   by 0x5C3BAD: dispatch_command(enum_server_command, THD*, char*, unsigned) (sql_parse.cc:1130)
   by 0x5C5017: do_command(THD*) (sql_parse.cc:802)
   by 0x68A400: do_handle_one_connection(THD*) (sql_connect.cc:1192)

This leak seems to be in the implementation of ALTER TABLE. The stack trace also contains references to plugins, and the leak is only found when running tests related to the semisync plugin. So it is not completely clear the leak is related to ALTER TABLE or to plugins/semisync.

How to repeat:
Read the log.
[8 Sep 2010 13:59] Sven Sandberg
See also BUG#56649, BUG#56650, and BUG#56651.
[31 Jan 2011 9:22] Jon Olav Hauglid
This looks like a plugin issue rather than an issue with ALTER TABLE.
The failing test is fulltext_plugin. The bytes that are leaked are allocated
by my_strdup() in sql_plugin.cc 

      /* Here we do anything special that may be required of the data types */

      if ((pi->plugin_var->flags & PLUGIN_VAR_TYPEMASK) == PLUGIN_VAR_STR &&
          pi->plugin_var->flags & PLUGIN_VAR_MEMALLOC)
      {
         char **pp= (char**) (thd->variables.dynamic_variables_ptr +
                             *(int*)(pi->plugin_var + 1));
         if ((*pp= *(char**) (global_system_variables.dynamic_variables_ptr +
                             *(int*)(pi->plugin_var + 1))))
           *pp= my_strdup(*pp, MYF(MY_WME|MY_FAE));
      }
    }

(Is the second if-statement really supposed to have an assignment and not a comparison?)

This code block is only hit by fulltext_plugin.test in the whole MTR test suite.
It is called when MyISAM tries to get the value of the sort_buffer_size system variable.
[10 Nov 2011 19:00] Paul Dubois
Noted in 5.5.19, 5.6.4 changelogs.

If a plugin was uninstalled, thread local variables for plugin
variables of string type with wth PLUGIN_VAR_MEMALLOC flag were not
freed.