summaryrefslogtreecommitdiff
path: root/sql
diff options
context:
space:
mode:
authorunknown <sasha@mysql.sashanet.com>2000-12-09 14:28:51 -0700
committerunknown <sasha@mysql.sashanet.com>2000-12-09 14:28:51 -0700
commit8beb43501be6bb4a4bd09e2b0aadc815dcc2f606 (patch)
treee1d361e164277c92682635c15be624dce98c7c72 /sql
parent701af104149fc90dc61267a0dc0f67694c8ac40b (diff)
downloadmariadb-git-8beb43501be6bb4a4bd09e2b0aadc815dcc2f606.tar.gz
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
Diffstat (limited to 'sql')
-rw-r--r--sql/mini_client.cc5
-rw-r--r--sql/mysqld.cc1
-rw-r--r--sql/slave.cc45
-rw-r--r--sql/slave.h3
-rw-r--r--sql/sql_class.cc2
-rw-r--r--sql/sql_repl.cc27
6 files changed, 67 insertions, 16 deletions
diff --git a/sql/mini_client.cc b/sql/mini_client.cc
index 3520062e052..11b0b111ec4 100644
--- a/sql/mini_client.cc
+++ b/sql/mini_client.cc
@@ -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));
diff --git a/sql/mysqld.cc b/sql/mysqld.cc
index 63034e98f7d..f10b367e36a 100644
--- a/sql/mysqld.cc
+++ b/sql/mysqld.cc
@@ -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 */
diff --git a/sql/slave.cc b/sql/slave.cc
index b68dc8023ae..e6262ba15c3 100644
--- a/sql/slave.cc
+++ b/sql/slave.cc
@@ -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);
diff --git a/sql/slave.h b/sql/slave.h
index b4fb16b4b07..c26be966fc3 100644
--- a/sql/slave.h
+++ b/sql/slave.h
@@ -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;
diff --git a/sql/sql_class.cc b/sql/sql_class.cc
index b310d0f44bb..0587ad6f31c 100644
--- a/sql/sql_class.cc
+++ b/sql/sql_class.cc
@@ -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)
diff --git a/sql/sql_repl.cc b/sql/sql_repl.cc
index 72d83419fe3..6dd9d805183 100644
--- a/sql/sql_repl.cc
+++ b/sql/sql_repl.cc
@@ -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);
}