Skip to content

Commit

Permalink
MDEV-31636 Memory leak in Sys_var_gtid_binlog_state::do_check()
Browse files Browse the repository at this point in the history
Move memory allocations performed during Sys_var_gtid_binlog_state::do_check
to Sys_var_gtid_binlog_state::global_update where they will be freed before
the latter method returns.
  • Loading branch information
DaveGosselin-MariaDB committed Sep 18, 2024
1 parent 450040e commit 257a8e3
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 30 deletions.
8 changes: 8 additions & 0 deletions mysql-test/main/mdev-31636.result
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
RESET MASTER;
SET
@@global.gtid_binlog_state='1-1-101,2-1-2002',
@@global.slave_parallel_mode=x;
ERROR 42000: Variable 'slave_parallel_mode' can't be set to the value of 'x'
SELECT @@global.gtid_binlog_state;
@@global.gtid_binlog_state

7 changes: 7 additions & 0 deletions mysql-test/main/mdev-31636.test
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
--source include/have_log_bin.inc
RESET MASTER;
--error ER_WRONG_VALUE_FOR_VAR
SET
@@global.gtid_binlog_state='1-1-101,2-1-2002',
@@global.slave_parallel_mode=x;
SELECT @@global.gtid_binlog_state;
58 changes: 28 additions & 30 deletions sql/sys_vars.cc
Original file line number Diff line number Diff line change
Expand Up @@ -2016,15 +2016,6 @@ struct gtid_binlog_state_data { rpl_gtid *list; uint32 list_len; };
bool
Sys_var_gtid_binlog_state::do_check(THD *thd, set_var *var)
{
String str, *res;
struct gtid_binlog_state_data *data;
rpl_gtid *list;
uint32 list_len;

DBUG_ASSERT(var->type == OPT_GLOBAL);

if (!(res= var->value->val_str(&str)))
return true;
if (thd->in_active_multi_stmt_transaction())
{
my_error(ER_CANT_DO_THIS_DURING_AN_TRANSACTION, MYF(0));
Expand All @@ -2040,6 +2031,31 @@ Sys_var_gtid_binlog_state::do_check(THD *thd, set_var *var)
my_error(ER_BINLOG_MUST_BE_EMPTY, MYF(0));
return true;
}
return false;
}


bool
Sys_var_gtid_binlog_state::global_update(THD *thd, set_var *var)
{
DBUG_ASSERT(var->type == OPT_GLOBAL);

if (!var->value)
{
my_error(ER_NO_DEFAULT, MYF(0), var->var->name.str);
return true;
}

bool result;
String str, *res;
struct gtid_binlog_state_data *data;
rpl_gtid *list;
uint32 list_len;

DBUG_ASSERT(var->type == OPT_GLOBAL);

if (!(res= var->value->val_str(&str)))
return true;
if (res->length() == 0)
{
list= NULL;
Expand All @@ -2061,31 +2077,13 @@ Sys_var_gtid_binlog_state::do_check(THD *thd, set_var *var)
data->list= list;
data->list_len= list_len;
var->save_result.ptr= data;
return false;
}


bool
Sys_var_gtid_binlog_state::global_update(THD *thd, set_var *var)
{
bool res;

DBUG_ASSERT(var->type == OPT_GLOBAL);

if (!var->value)
{
my_error(ER_NO_DEFAULT, MYF(0), var->var->name.str);
return true;
}

struct gtid_binlog_state_data *data=
(struct gtid_binlog_state_data *)var->save_result.ptr;

mysql_mutex_unlock(&LOCK_global_system_variables);
res= (reset_master(thd, data->list, data->list_len, 0) != 0);
result= (reset_master(thd, data->list, data->list_len, 0) != 0);
mysql_mutex_lock(&LOCK_global_system_variables);
my_free(data->list);
my_free(data);
return res;
return result;
}


Expand Down

0 comments on commit 257a8e3

Please sign in to comment.