From f67896bb316b3cbf04049185da70cf73370dd5f2 Mon Sep 17 00:00:00 2001 From: "hf@deer.(none)" <> Date: Wed, 27 Jul 2005 17:34:20 +0500 Subject: [PATCH 1/4] Fix for bug #12177 (error file isn't closed) --- libmysqld/lib_sql.cc | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/libmysqld/lib_sql.cc b/libmysqld/lib_sql.cc index 0ec7d161f24..4b05dd70e35 100644 --- a/libmysqld/lib_sql.cc +++ b/libmysqld/lib_sql.cc @@ -320,7 +320,8 @@ extern "C" static my_bool org_my_init_done; my_bool server_inited; -char ** copy_arguments_ptr= 0; +char ** copy_arguments_ptr= 0; +static FILE *errorlog_file=0; int STDCALL mysql_server_init(int argc, char **argv, char **groups) { @@ -421,7 +422,7 @@ int STDCALL mysql_server_init(int argc, char **argv, char **groups) opt_error_log= 1; // Too long file name else { - freopen(log_error_file, "a+", stderr); + errorlog_file= freopen(log_error_file, "a+", stderr); } } @@ -626,6 +627,8 @@ void STDCALL mysql_server_end() my_free((char*) copy_arguments_ptr, MYF(MY_ALLOW_ZERO_PTR)); copy_arguments_ptr=0; clean_up(0); + if (errorlog_file) + fclose(errorlog_file); /* If library called my_init(), free memory allocated by it */ if (!org_my_init_done) my_end(0); From 30dd658d4153a399c3379e0d526fd87d36077b2c Mon Sep 17 00:00:00 2001 From: "hf@deer.(none)" <> Date: Wed, 27 Jul 2005 19:39:59 +0500 Subject: [PATCH 2/4] addition to the fix for bug #12177(error log file isn't closed) --- libmysqld/lib_sql.cc | 3 +++ 1 file changed, 3 insertions(+) diff --git a/libmysqld/lib_sql.cc b/libmysqld/lib_sql.cc index 4b05dd70e35..b71b442b4ca 100644 --- a/libmysqld/lib_sql.cc +++ b/libmysqld/lib_sql.cc @@ -628,7 +628,10 @@ void STDCALL mysql_server_end() copy_arguments_ptr=0; clean_up(0); if (errorlog_file) + { fclose(errorlog_file); + errorlog_file=0; + } /* If library called my_init(), free memory allocated by it */ if (!org_my_init_done) my_end(0); From 9d39e4a59c3fbcad862784085fbd81d2692759f5 Mon Sep 17 00:00:00 2001 From: "hf@deer.(none)" <> Date: Thu, 28 Jul 2005 17:18:24 +0500 Subject: [PATCH 3/4] Additional fix for #12177 (stderr isn't closed) --- libmysqld/lib_sql.cc | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/libmysqld/lib_sql.cc b/libmysqld/lib_sql.cc index b71b442b4ca..d607e1dcf43 100644 --- a/libmysqld/lib_sql.cc +++ b/libmysqld/lib_sql.cc @@ -627,14 +627,14 @@ void STDCALL mysql_server_end() my_free((char*) copy_arguments_ptr, MYF(MY_ALLOW_ZERO_PTR)); copy_arguments_ptr=0; clean_up(0); + /* If library called my_init(), free memory allocated by it */ + if (!org_my_init_done) + my_end(0); if (errorlog_file) { fclose(errorlog_file); errorlog_file=0; } - /* If library called my_init(), free memory allocated by it */ - if (!org_my_init_done) - my_end(0); } my_bool STDCALL mysql_thread_init() From 39ef54fd8e85f23790b8f343145ef76b807743b9 Mon Sep 17 00:00:00 2001 From: "hf@deer.(none)" <> Date: Thu, 4 Aug 2005 15:23:21 +0500 Subject: [PATCH 4/4] Fix for bug #12177 (errorlog file isn't closed) 4.1 version of the patch --- libmysql/libmysql.c | 7 +++++++ sql/mysql_priv.h | 1 + sql/mysqld.cc | 3 ++- 3 files changed, 10 insertions(+), 1 deletion(-) diff --git a/libmysql/libmysql.c b/libmysql/libmysql.c index e5681edd3d8..7c6d140d2ef 100644 --- a/libmysql/libmysql.c +++ b/libmysql/libmysql.c @@ -188,6 +188,13 @@ void STDCALL mysql_server_end() mysql_thread_end(); free_charsets(); mysql_client_init= org_my_init_done= 0; +#ifdef EMBEDDED_SERVER + if (stderror_file) + { + fclose(stderror_file); + stderror_file= 0; + } +#endif } static MYSQL_PARAMETERS mysql_internal_parameters= diff --git a/sql/mysql_priv.h b/sql/mysql_priv.h index 6969433649f..c8a4c4740ef 100644 --- a/sql/mysql_priv.h +++ b/sql/mysql_priv.h @@ -941,6 +941,7 @@ extern char *default_tz_name; extern MYSQL_LOG mysql_log,mysql_update_log,mysql_slow_log,mysql_bin_log; extern FILE *bootstrap_file; +extern FILE *stderror_file; extern pthread_key(MEM_ROOT**,THR_MALLOC); extern pthread_mutex_t LOCK_mysql_create_db,LOCK_Acl,LOCK_open, LOCK_thread_count,LOCK_mapped_file,LOCK_user_locks, LOCK_status, diff --git a/sql/mysqld.cc b/sql/mysqld.cc index 6bbd6f79aa2..9177703599c 100644 --- a/sql/mysqld.cc +++ b/sql/mysqld.cc @@ -382,6 +382,7 @@ Le_creator le_creator; FILE *bootstrap_file; +FILE *stderror_file=0; I_List replicate_rewrite_db; I_List replicate_do_db, replicate_ignore_db; @@ -2767,7 +2768,7 @@ server."); #ifndef EMBEDDED_LIBRARY if (freopen(log_error_file, "a+", stdout)) #endif - freopen(log_error_file, "a+", stderr); + stderror_file= freopen(log_error_file, "a+", stderr); } }