Commit 8beb4350 authored by unknown's avatar unknown

fixed up leaks found by --exit-info=256

better error diagnostic in SLAVE START


sql/mini_client.cc:
  if we fail to connect, we need to free the inited structure
sql/mysqld.cc:
  added end_slave() for slave cleanup
sql/slave.cc:
  fixed serveral memory leaks
sql/slave.h:
  added end_master_info() for clean up
sql/sql_class.cc:
  not changed
sql/sql_repl.cc:
  initialize master info before creating slave thread in SLAVE START -
  this way we can easily send an error to the client if something is 
  wrong in init_master_info
parent 701af104
......@@ -386,7 +386,10 @@ my_bool STDCALL mc_mysql_reconnect(MYSQL *mysql)
if (!mc_mysql_connect(&tmp_mysql,mysql->host,mysql->user,mysql->passwd,
mysql->db, mysql->port, mysql->unix_socket,
mysql->client_flag))
DBUG_RETURN(1);
{
mc_mysql_close(&tmp_mysql);
DBUG_RETURN(1);
}
tmp_mysql.free_me=mysql->free_me;
mysql->free_me=0;
bzero((char*) &mysql->options,sizeof(&mysql->options));
......
......@@ -614,6 +614,7 @@ void clean_up(void)
#ifndef __WIN__
(void) my_delete(pidfile_name,MYF(0)); // This may not always exist
#endif
end_slave();
my_thread_end();
/* Tell main we are ready */
......
......@@ -167,6 +167,30 @@ int add_wild_table_rule(DYNAMIC_ARRAY* a, const char* table_spec)
return 0;
}
static void free_string_array(DYNAMIC_ARRAY *a)
{
uint i;
for(i = 0; i < a->elements; i++)
{
char* p;
get_dynamic(a, (gptr)&p, i);
my_free(p, MYF(MY_WME));
}
delete_dynamic(a);
}
void end_slave()
{
end_master_info(&glob_mi);
if(do_table_inited)
hash_free(&replicate_do_table);
if(ignore_table_inited)
hash_free(&replicate_ignore_table);
if(wild_do_table_inited)
free_string_array(&replicate_wild_do_table);
if(wild_ignore_table_inited)
free_string_array(&replicate_wild_ignore_table);
}
static inline bool slave_killed(THD* thd)
{
......@@ -398,8 +422,21 @@ int fetch_nx_table(THD* thd, MASTER_INFO* mi)
return error;
}
void end_master_info(MASTER_INFO* mi)
{
if(mi->fd >= 0)
{
end_io_cache(&mi->file);
(void)my_close(mi->fd, MYF(MY_WME));
mi->fd = -1;
}
mi->inited = 0;
}
int init_master_info(MASTER_INFO* mi)
{
if(mi->inited)
return 0;
int fd;
MY_STAT stat_area;
char fname[FN_REFLEN+128];
......@@ -440,7 +477,7 @@ int init_master_info(MASTER_INFO* mi)
mi->connect_retry = master_connect_retry;
}
else
else // file exists
{
if(fd >= 0)
reinit_io_cache(&mi->file, READ_CACHE, 0L,0,0);
......@@ -897,8 +934,11 @@ static int exec_event(THD* thd, NET* net, MASTER_INFO* mi, int event_len)
sql_print_error("Slave: error '%s' running load data infile ",
ER(sql_error));
delete ev;
free_root(&thd->mem_root,0);
return 1;
}
free_root(&thd->mem_root,0);
delete ev;
if(thd->fatal_error)
......@@ -932,6 +972,7 @@ static int exec_event(THD* thd, NET* net, MASTER_INFO* mi, int event_len)
mi->log_file_name[ident_len] = 0;
mi->pos = 4; // skip magic number
flush_master_info(mi);
delete ev;
break;
}
......@@ -950,6 +991,7 @@ static int exec_event(THD* thd, NET* net, MASTER_INFO* mi, int event_len)
}
mi->inc_pending(event_len);
delete ev;
break;
}
}
......@@ -1157,6 +1199,7 @@ position %ld",
thd->temporary_tables = 0; // remove tempation from destructor to close them
pthread_cond_broadcast(&COND_slave_stopped); // tell the world we are done
pthread_mutex_unlock(&LOCK_slave);
net_end(&thd->net); // destructor will not free it, because we are weird
delete thd;
my_thread_end();
pthread_exit(0);
......
......@@ -26,7 +26,6 @@ typedef struct st_master_info
{
pthread_mutex_destroy(&lock);
}
inline void inc_pending(ulonglong val)
{
pending += val;
......@@ -81,7 +80,9 @@ int add_wild_table_rule(DYNAMIC_ARRAY* a, const char* table_spec);
void init_table_rule_hash(HASH* h, bool* h_inited);
void init_table_rule_array(DYNAMIC_ARRAY* a, bool* a_inited);
void end_slave(); // clean up
int init_master_info(MASTER_INFO* mi);
void end_master_info(MASTER_INFO* mi);
extern bool opt_log_slave_updates ;
pthread_handler_decl(handle_slave,arg);
extern bool volatile abort_loop, abort_slave;
......
......@@ -139,7 +139,7 @@ THD::~THD()
if (net.vio)
{
vio_delete(net.vio);
net_end(&net);
net_end(&net);
}
ha_rollback(this);
if (locked_tables)
......
......@@ -503,17 +503,20 @@ int start_slave(THD* thd , bool net_report)
return 1;
pthread_mutex_lock(&LOCK_slave);
if(!slave_running)
if(glob_mi.inited && glob_mi.host && server_id_supplied)
{
pthread_t hThread;
if(pthread_create(&hThread, &connection_attrib, handle_slave, 0))
{
err = "cannot create slave thread";
}
}
else
err = "Master host not set, master info not initialized, or server id \
not configured";
{
if(init_master_info(&glob_mi))
err = "Could not initialize master info";
else if(server_id_supplied && *glob_mi.host)
{
pthread_t hThread;
if(pthread_create(&hThread, &connection_attrib, handle_slave, 0))
{
err = "cannot create slave thread";
}
}
else
err = "Master host not set, or server id not configured";
}
else
err = "Slave already running";
......@@ -578,7 +581,7 @@ void reset_slave()
if(my_stat(fname, &stat_area, MYF(0)))
if(my_delete(fname, MYF(MY_WME)))
return;
end_master_info(&glob_mi);
if(slave_was_running)
start_slave(0,0);
}
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment