LP #1674476: tokudb_backup_last_error_string variable causes memory leak on shutdown

Description

**Reported in Launchpad by Vlad Lesin last update 23-03-2017 12:25:18

tokudb_backup_last_error_string variable causes memory leak on shutdown.

This is valgrind report:

68 bytes in 1 blocks are definitely lost in loss record 4 of 5
at 0x1874A91: my_malloc (my_malloc.c:62)
by 0x187510E: my_strdup (my_malloc.c:309)
by 0x2BA29DAA: ???
by 0x2BA29F1C: ???
by 0x2BA2BF80: ???
by 0x2BA2C7AB: ???
by 0x155F448: sys_var_pluginvar::do_check(THD*, set_var*) (sql_plugin.cc:3524)
by 0x145CB7D: sys_var::check(THD*, set_var*) (set_var.cc:241)
by 0x145DD0A: set_var::check(THD*) (set_var.cc:757)
by 0x145D76A: sql_set_variables(THD*, List<set_var_base>*, bool) (set_var.cc:665)
by 0x152D67F: mysql_execute_command(THD*, bool) (sql_parse.cc:3896)
by 0x1533116: mysql_parse(THD*, Parser_state*) (sql_parse.cc:5927)
by 0x1527936: dispatch_command(THD*, COM_DATA const*, enum_server_command) (sql_parse.cc:1493)
by 0x152677C: do_command(THD*) (sql_parse.cc:1021)
by 0x166CAAF: handle_connection (connection_handler_per_thread.cc:312)
by 0x18CDE7A: pfs_spawn_thread (pfs.cc:2188)

which is caused by the following code:

static void tokudb_backup_set_error(THD *thd, int error, const char *error_string) {
THDVAR(thd, last_error) = error;
char *old_error_string = THDVAR(thd, last_error_string);
if (error_string)
THDVAR(thd, last_error_string) =
my_strdup(tokudb_backup_mem_key, error_string, MYF(MY_FAE));
else
THDVAR(thd, last_error_string) = NULL;
if (old_error_string)
my_free(old_error_string);
}

i.e. the memory is allocated for error string and deallocated only when new error string is set.

Environment

None

Smart Checklist

Activity

Show:

lpjirasync January 22, 2018 at 2:33 PM

Done

Details

Assignee

Reporter

Priority

Smart Checklist

Created January 22, 2018 at 2:32 PM
Updated January 22, 2018 at 2:33 PM
Resolved January 22, 2018 at 2:33 PM