Skip to content

Commit 832743f

Browse files
committed
fix a memory leak in sysvars
GET_STR_ALLOC options are allocated by my_getopt in init_one_value(). but maria-backup never calls handle_option() for them at all, so Sys_var_charptr_base needs a protection for partially-initialized variables. followup for f33367f
1 parent 53504fa commit 832743f

File tree

2 files changed

+3
-16
lines changed

2 files changed

+3
-16
lines changed

sql/sys_vars.inl

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -520,14 +520,11 @@ public:
520520
(think of an exit because of an error right after my_getopt)
521521
*/
522522
option.var_type|= (flags & ALLOCATED) ? GET_STR_ALLOC : GET_STR;
523-
if (def_val && (flags & ALLOCATED))
524-
global_var(const char*)= my_strdup(PSI_INSTRUMENT_ME, def_val, MYF(0));
525-
else
526-
global_var(const char*)= def_val;
523+
global_var(const char*)= def_val;
527524
}
528525
void cleanup() override
529526
{
530-
if (flags & ALLOCATED)
527+
if (flags & ALLOCATED && global_var(intptr) != (intptr)option.def_value)
531528
{
532529
my_free(global_var(char*));
533530
global_var(char *)= NULL;
@@ -583,8 +580,7 @@ public:
583580
}
584581
void global_update_finish(char *new_val)
585582
{
586-
if (flags & ALLOCATED)
587-
my_free(global_var(char*));
583+
cleanup();
588584
flags|= ALLOCATED;
589585
global_var(char*)= new_val;
590586
}

sql/wsrep_var.cc

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -33,15 +33,6 @@ ulong wsrep_reject_queries;
3333

3434
int wsrep_init_vars()
3535
{
36-
my_free((char*) wsrep_provider);
37-
my_free((char*) wsrep_provider_options);
38-
my_free((char*) wsrep_cluster_address);
39-
my_free((char*) wsrep_cluster_name);
40-
my_free((char*) wsrep_node_name);
41-
my_free((char*) wsrep_node_address);
42-
my_free((char*) wsrep_node_incoming_address);
43-
my_free((char*) wsrep_start_position);
44-
4536
wsrep_provider = my_strdup(PSI_INSTRUMENT_ME, WSREP_NONE, MYF(MY_WME));
4637
wsrep_provider_options= my_strdup(PSI_INSTRUMENT_ME, "", MYF(MY_WME));
4738
wsrep_cluster_address = my_strdup(PSI_INSTRUMENT_ME, "", MYF(MY_WME));

0 commit comments

Comments
 (0)