summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorunknown <monty@mashka.mysql.fi>2002-12-05 03:40:33 +0200
committerunknown <monty@mashka.mysql.fi>2002-12-05 03:40:33 +0200
commit591b058518dcbc736398d64e8bfd1ac43099323e (patch)
treeacbe11728f20cce01476a8928088773d8016fe76
parent7280bddb710be4ac1c7acc9f9f7daaa2eea850ff (diff)
downloadmariadb-git-591b058518dcbc736398d64e8bfd1ac43099323e.tar.gz
Removed copying of parameters as this leads to memory leaks in embedded server.
Fixed 'not initialized' memory error. mysql-test/mysql-test-run.sh: Updates to be able to more easily use --valgrind mysql-test/r/alter_table.result: Added missing drop table mysql-test/t/alter_table.test: Added missing drop table sql/field.cc: Simple optimizations sql/ha_innodb.cc: Remove copying of parameters as this leads to memory leaks in MySQL. Should be instead fixed by, in embedded server, make a temporary copy of all parameters and free them on server-end sql/log.cc: Simple optimization sql/mysql_priv.h: Move external reference to struct to include file sql/mysqld.cc: Added safety asserts sql/sql_class.cc: Fixed non fatal 'not initialized memory reference error' in thread init sql/sql_udf.cc: Clear current_thd for global thread strings/strto.c: Simple optimization
-rw-r--r--mysql-test/mysql-test-run.sh73
-rw-r--r--mysql-test/r/alter_table.result2
-rw-r--r--mysql-test/t/alter_table.test2
-rw-r--r--sql/field.cc22
-rw-r--r--sql/ha_innodb.cc30
-rw-r--r--sql/log.cc70
-rw-r--r--sql/mysql_priv.h1
-rw-r--r--sql/mysqld.cc3
-rw-r--r--sql/sql_class.cc3
-rw-r--r--sql/sql_udf.cc2
-rw-r--r--strings/strto.c5
11 files changed, 114 insertions, 99 deletions
diff --git a/mysql-test/mysql-test-run.sh b/mysql-test/mysql-test-run.sh
index 4317ba0e749..928beaf0aa4 100644
--- a/mysql-test/mysql-test-run.sh
+++ b/mysql-test/mysql-test-run.sh
@@ -19,7 +19,7 @@ TZ=GMT-3; export TZ # for UNIX_TIMESTAMP tests to work
# Program Definitions
#--
-PATH=/bin:/usr/bin:/usr/local/bin:/usr/bsd:/usr/X11R6/bin:/usr/openwin/bin:/usr/bin/X11
+PATH=/bin:/usr/bin:/usr/local/bin:/usr/bsd:/usr/X11R6/bin:/usr/openwin/bin:/usr/bin/X11:$PATH
MASTER_40_ARGS="--rpl-recovery-rank=1 --init-rpl-role=master"
# Standard functions
@@ -47,13 +47,17 @@ which ()
sleep_until_file_deleted ()
{
- file=$1
+ pid=$1;
+ file=$2
loop=$SLEEP_TIME_FOR_DELETE
while (test $loop -gt 0)
do
if [ ! -r $file ]
then
- sleep $SLEEP_TIME_AFTER_RESTART
+ if test $pid != "0"
+ then
+ wait_for_pid $pid
+ fi
return
fi
sleep 1
@@ -79,6 +83,13 @@ sleep_until_file_created ()
exit 1;
}
+# For the future
+
+wait_for_pid()
+{
+ pid=$1
+}
+
# No paths below as we can't be sure where the program is!
SED=sed
@@ -152,6 +163,7 @@ TOT_TEST=0
USERT=0
SYST=0
REALT=0
+FAST_START=""
MYSQL_TMP_DIR=$MYSQL_TEST_DIR/var/tmp
SLAVE_LOAD_TMPDIR=../../var/tmp #needs to be same length to test logging
RES_SPACE=" "
@@ -314,7 +326,7 @@ while test $# -gt 0; do
VALGRIND="valgrind --alignment=8 --leak-check=yes"
EXTRA_MASTER_MYSQLD_OPT="$EXTRA_MASTER_MYSQLD_OPT --skip-safemalloc"
EXTRA_SLAVE_MYSQLD_OPT="$EXTRA_SLAVE_MYSQLD_OPT --skip-safemalloc"
- SLEEP_TIME_AFTER_RESTART=120
+ #SLEEP_TIME_AFTER_RESTART=120
SLEEP_TIME_FOR_DELETE=120
;;
--valgrind-options=*)
@@ -335,6 +347,9 @@ while test $# -gt 0; do
--debug=d:t:i:O,$MYSQL_TEST_DIR/var/log/slave.trace"
EXTRA_MYSQL_TEST_OPT="$EXTRA_MYSQL_TEST_OPT --debug"
;;
+ --fast)
+ FAST_START=1
+ ;;
-- ) shift; break ;;
--* ) $ECHO "Unrecognized option: $1"; exit 1 ;;
* ) break ;;
@@ -731,12 +746,19 @@ EOF
manager_term()
{
- ident=$1
+ pid=$1
+ ident=$2
shift
if [ $USE_MANAGER = 0 ] ; then
- $MYSQLADMIN --no-defaults -uroot --socket=$MYSQL_TMP_DIR/$ident.sock -O \
- connect_timeout=5 -O shutdown_timeout=20 shutdown >> $MYSQL_MANAGER_LOG 2>&1
- return
+ $MYSQLADMIN --no-defaults -uroot --socket=$MYSQL_TMP_DIR/$ident.sock --connect_timeout=5 --shutdown_timeout=20 shutdown >> $MYSQL_MANAGER_LOG 2>&1
+ res=$?
+ # Some systems require an extra connect
+ $MYSQLADMIN --no-defaults -uroot --socket=$MYSQL_TMP_DIR/$ident.sock --connect_timeout=1 ping >> $MYSQL_MANAGER_LOG 2>&1
+ if test $res = 0
+ then
+ wait_for_pid $pid
+ fi
+ return $res
fi
$MYSQL_MANAGER_CLIENT $MANAGER_QUIET_OPT --user=$MYSQL_MANAGER_USER \
--password=$MYSQL_MANAGER_PW --port=$MYSQL_MANAGER_PORT <<EOF
@@ -978,12 +1000,13 @@ stop_slave ()
fi
if [ x$this_slave_running = x1 ]
then
- manager_term $slave_ident
+ pid=`$CAT $slave_pid`
+ manager_term $pid $slave_ident
if [ $? != 0 ] && [ -f $slave_pid ]
then # try harder!
$ECHO "slave not cooperating with mysqladmin, will try manual kill"
- kill `$CAT $slave_pid`
- sleep_until_file_deleted $slave_pid
+ kill $pid
+ sleep_until_file_deleted $pid $slave_pid
if [ -f $slave_pid ] ; then
$ECHO "slave refused to die. Sending SIGKILL"
kill -9 `$CAT $slave_pid`
@@ -1002,12 +1025,13 @@ stop_master ()
{
if [ x$MASTER_RUNNING = x1 ]
then
- manager_term master
+ pid=`$CAT $MASTER_MYPID`
+ manager_term $pid master
if [ $? != 0 ] && [ -f $MASTER_MYPID ]
then # try harder!
$ECHO "master not cooperating with mysqladmin, will try manual kill"
- kill `$CAT $MASTER_MYPID`
- sleep_until_file_deleted $MASTER_MYPID
+ kill $pid
+ sleep_until_file_deleted $pid $MASTER_MYPID
if [ -f $MASTER_MYPID ] ; then
$ECHO "master refused to die. Sending SIGKILL"
kill -9 `$CAT $MASTER_MYPID`
@@ -1228,14 +1252,19 @@ run_testcase ()
if [ -z "$USE_RUNNING_SERVER" ]
then
- # Ensure that no old mysqld test servers are running
- $MYSQLADMIN --no-defaults --socket=$MASTER_MYSOCK -u root -O connect_timeout=5 -O shutdown_timeout=20 shutdown > /dev/null 2>&1
- $MYSQLADMIN --no-defaults --socket=$SLAVE_MYSOCK -u root -O connect_timeout=5 -O shutdown_timeout=20 shutdown > /dev/null 2>&1
- $MYSQLADMIN --no-defaults --host=$hostname --port=$MASTER_MYPORT -u root -O connect_timeout=5 -O shutdown_timeout=20 shutdown > /dev/null 2>&1
- $MYSQLADMIN --no-defaults --host=$hostname --port=$SLAVE_MYPORT -u root -O connect_timeout=5 -O shutdown_timeout=20 shutdown > /dev/null 2>&1
- $MYSQLADMIN --no-defaults --host=$hostname --port=`expr $SLAVE_MYPORT + 1` -u root -O connect_timeout=5 -O shutdown_timeout=20 shutdown > /dev/null 2>&1
- sleep_until_file_deleted $MASTER_MYPID
- sleep_until_file_deleted $SLAVE_MYPID
+ if [ -z "$FAST_START" ]
+ then
+ # Ensure that no old mysqld test servers are running
+ $MYSQLADMIN --no-defaults --socket=$MASTER_MYSOCK -u root -O connect_timeout=5 -O shutdown_timeout=20 shutdown > /dev/null 2>&1
+ $MYSQLADMIN --no-defaults --socket=$SLAVE_MYSOCK -u root -O connect_timeout=5 -O shutdown_timeout=20 shutdown > /dev/null 2>&1
+ $MYSQLADMIN --no-defaults --host=$hostname --port=$MASTER_MYPORT -u root -O connect_timeout=5 -O shutdown_timeout=20 shutdown > /dev/null 2>&1
+ $MYSQLADMIN --no-defaults --host=$hostname --port=$SLAVE_MYPORT -u root -O connect_timeout=5 -O shutdown_timeout=20 shutdown > /dev/null 2>&1
+ $MYSQLADMIN --no-defaults --host=$hostname --port=`expr $SLAVE_MYPORT + 1` -u root -O connect_timeout=5 -O shutdown_timeout=20 shutdown > /dev/null 2>&1
+ sleep_until_file_deleted 0 $MASTER_MYPID
+ sleep_until_file_deleted 0 $SLAVE_MYPID
+ else
+ rm $MASTER_MYPID $SLAVE_MYPID
+ fi
# Kill any running managers
if [ -f "$MANAGER_PID_FILE" ]
diff --git a/mysql-test/r/alter_table.result b/mysql-test/r/alter_table.result
index 1d6d69465da..096ef2fd79e 100644
--- a/mysql-test/r/alter_table.result
+++ b/mysql-test/r/alter_table.result
@@ -1,4 +1,4 @@
-drop table if exists t1;
+drop table if exists t1,t2;
create table t1 (
col1 int not null auto_increment primary key,
col2 varchar(30) not null,
diff --git a/mysql-test/t/alter_table.test b/mysql-test/t/alter_table.test
index 2b329f3ec6e..1c3987e2a31 100644
--- a/mysql-test/t/alter_table.test
+++ b/mysql-test/t/alter_table.test
@@ -2,7 +2,7 @@
# Test of alter table
#
-drop table if exists t1;
+drop table if exists t1,t2;
create table t1 (
col1 int not null auto_increment primary key,
col2 varchar(30) not null,
diff --git a/sql/field.cc b/sql/field.cc
index e631ade16b1..afd594b7045 100644
--- a/sql/field.cc
+++ b/sql/field.cc
@@ -1491,12 +1491,14 @@ void Field_medium::sql_type(String &res) const
void Field_long::store(const char *from,uint len)
{
+ char *end;
while (len && isspace(*from))
{
len--; from++;
}
long tmp;
String tmp_str(from,len);
+ from= tmp_str.c_ptr(); // Add end null if needed
errno=0;
if (unsigned_flag)
{
@@ -1506,11 +1508,13 @@ void Field_long::store(const char *from,uint len)
errno=ERANGE;
}
else
- tmp=(long) strtoul(tmp_str.c_ptr(),NULL,10);
+ tmp=(long) strtoul(from, &end, 10);
}
else
- tmp=strtol(tmp_str.c_ptr(),NULL,10);
- if (errno || current_thd->count_cuted_fields && !test_if_int(from,len))
+ tmp=strtol(from, &end, 10);
+ if (errno ||
+ (from+len != end && current_thd->count_cuted_fields &&
+ !test_if_int(from,len)))
current_thd->cuted_fields++;
#ifdef WORDS_BIGENDIAN
if (table->db_low_byte_first)
@@ -1719,12 +1723,14 @@ void Field_long::sql_type(String &res) const
void Field_longlong::store(const char *from,uint len)
{
+ char *end;
while (len && isspace(*from))
{ // For easy error check
len--; from++;
}
longlong tmp;
String tmp_str(from,len);
+ from= tmp_str.c_ptr(); // Add end null if needed
errno=0;
if (unsigned_flag)
{
@@ -1734,12 +1740,14 @@ void Field_longlong::store(const char *from,uint len)
errno=ERANGE;
}
else
- tmp=(longlong) strtoull(tmp_str.c_ptr(),NULL,10);
+ tmp=(longlong) strtoull(from, &end, 10);
}
else
- tmp=strtoll(tmp_str.c_ptr(),NULL,10);
- if (errno || current_thd->count_cuted_fields && !test_if_int(from,len))
- current_thd->cuted_fields++;
+ tmp=strtoll(from, &end, 10);
+ if (errno ||
+ (from+len != end && current_thd->count_cuted_fields &&
+ !test_if_int(from,len)))
+ current_thd->cuted_fields++;
#ifdef WORDS_BIGENDIAN
if (table->db_low_byte_first)
{
diff --git a/sql/ha_innodb.cc b/sql/ha_innodb.cc
index 343b8477d38..2868011c443 100644
--- a/sql/ha_innodb.cc
+++ b/sql/ha_innodb.cc
@@ -674,36 +674,6 @@ innobase_init(void)
/* Set InnoDB initialization parameters according to the values
read from MySQL .cnf file */
- /* --------------------------------------------------*/
- /* Make copies of all string-valued parameters, because after
- C# calls server_init(), it may move the parameter strings around */
-
- if (innobase_data_home_dir) {
- innobase_data_home_dir = my_strdup(
- innobase_data_home_dir,
- MYF(MY_WME));
- }
- if (innobase_data_file_path) {
- innobase_data_file_path = my_strdup(
- innobase_data_file_path,
- MYF(MY_WME));
- }
- if (innobase_log_group_home_dir) {
- innobase_log_group_home_dir = my_strdup(
- innobase_log_group_home_dir,
- MYF(MY_WME));
- }
- if (innobase_log_arch_dir) {
- innobase_log_arch_dir = my_strdup(
- innobase_log_arch_dir,
- MYF(MY_WME));
- }
- if (innobase_unix_file_flush_method) {
- innobase_unix_file_flush_method = my_strdup(
- innobase_unix_file_flush_method,
- MYF(MY_WME));
- }
-
/*--------------- Data files -------------------------*/
/* The default dir for data files is the datadir of MySQL */
diff --git a/sql/log.cc b/sql/log.cc
index 597985e8796..32dbdac1074 100644
--- a/sql/log.cc
+++ b/sql/log.cc
@@ -1053,40 +1053,44 @@ bool MYSQL_LOG::write(Log_event* event_info)
No check for auto events flag here - this write method should
never be called if auto-events are enabled
*/
- if (thd && thd->last_insert_id_used)
+ if (thd)
{
- Intvar_log_event e(thd,(uchar)LAST_INSERT_ID_EVENT,thd->last_insert_id);
- e.set_log_pos(this);
- if (thd->server_id)
- e.server_id = thd->server_id;
- if (e.write(file))
- goto err;
- }
- if (thd && thd->insert_id_used)
- {
- Intvar_log_event e(thd,(uchar)INSERT_ID_EVENT,thd->last_insert_id);
- e.set_log_pos(this);
- if (thd->server_id)
- e.server_id = thd->server_id;
- if (e.write(file))
- goto err;
- }
- if (thd && thd->rand_used)
- {
- Rand_log_event e(thd,thd->rand_saved_seed1,thd->rand_saved_seed2);
- e.set_log_pos(this);
- if (e.write(file))
- goto err;
- }
- if (thd && thd->variables.convert_set)
- {
- char buf[1024] = "SET CHARACTER SET ";
- char* p = strend(buf);
- p = strmov(p, thd->variables.convert_set->name);
- Query_log_event e(thd, buf, (ulong)(p - buf), 0);
- e.set_log_pos(this);
- if (e.write(file))
- goto err;
+ if (thd->last_insert_id_used)
+ {
+ Intvar_log_event e(thd,(uchar) LAST_INSERT_ID_EVENT,
+ thd->last_insert_id);
+ e.set_log_pos(this);
+ if (thd->server_id)
+ e.server_id = thd->server_id;
+ if (e.write(file))
+ goto err;
+ }
+ if (thd->insert_id_used)
+ {
+ Intvar_log_event e(thd,(uchar) INSERT_ID_EVENT,thd->last_insert_id);
+ e.set_log_pos(this);
+ if (thd->server_id)
+ e.server_id = thd->server_id;
+ if (e.write(file))
+ goto err;
+ }
+ if (thd->rand_used)
+ {
+ Rand_log_event e(thd,thd->rand_saved_seed1,thd->rand_saved_seed2);
+ e.set_log_pos(this);
+ if (e.write(file))
+ goto err;
+ }
+ if (thd->variables.convert_set)
+ {
+ char buf[256], *p;
+ p= strmov(strmov(buf, "SET CHARACTER SET "),
+ thd->variables.convert_set->name);
+ Query_log_event e(thd, buf, (ulong) (p - buf), 0);
+ e.set_log_pos(this);
+ if (e.write(file))
+ goto err;
+ }
}
event_info->set_log_pos(this);
if (event_info->write(file) ||
diff --git a/sql/mysql_priv.h b/sql/mysql_priv.h
index 7cfbd84a99d..ffdf74b412f 100644
--- a/sql/mysql_priv.h
+++ b/sql/mysql_priv.h
@@ -689,6 +689,7 @@ extern String empty_string;
extern SHOW_VAR init_vars[],status_vars[], internal_vars[];
extern struct system_variables global_system_variables;
extern struct system_variables max_system_variables;
+extern struct rand_struct sql_rand;
/* optional things, have_* variables */
diff --git a/sql/mysqld.cc b/sql/mysqld.cc
index a65cbd1139d..ecde4bc8645 100644
--- a/sql/mysqld.cc
+++ b/sql/mysqld.cc
@@ -32,6 +32,7 @@
#include <nisam.h>
#include <thr_alarm.h>
#include <ft_global.h>
+#include <assert.h>
#ifndef DBUG_OFF
#define ONE_THREAD
@@ -2091,6 +2092,7 @@ int main(int argc, char **argv)
(void) grant_init((THD*) 0);
init_max_user_conn();
init_update_queries();
+ DBUG_ASSERT(current_thd == 0);
#ifdef HAVE_DLOPEN
if (!opt_noacl)
@@ -2099,6 +2101,7 @@ int main(int argc, char **argv)
/* init_slave() must be called after the thread keys are created */
init_slave();
+ DBUG_ASSERT(current_thd == 0);
if (opt_bin_log && !server_id)
{
server_id= !master_host ? 1 : 2;
diff --git a/sql/sql_class.cc b/sql/sql_class.cc
index 8b276cf0d9b..5f73c6fa64e 100644
--- a/sql/sql_class.cc
+++ b/sql/sql_class.cc
@@ -37,7 +37,6 @@
#include <mysys_err.h>
#include <assert.h>
-extern struct rand_struct sql_rand;
/*****************************************************************************
** Instansiate templates
@@ -159,7 +158,7 @@ THD::THD():user_time(0),fatal_error(0),last_insert_id_used(0),
pthread_mutex_lock(&LOCK_thread_count);
ulong tmp=(ulong) (rnd(&sql_rand) * 3000000);
pthread_mutex_unlock(&LOCK_thread_count);
- randominit(&rand, tmp + (ulong) start_time, tmp + (ulong) thread_id);
+ randominit(&rand, tmp + (ulong) &rand, tmp + (ulong) ::query_id);
}
}
diff --git a/sql/sql_udf.cc b/sql/sql_udf.cc
index 420ec67f0c5..937d1e52656 100644
--- a/sql/sql_udf.cc
+++ b/sql/sql_udf.cc
@@ -202,6 +202,8 @@ void udf_init()
new_thd->version--; // Force close to free memory
close_thread_tables(new_thd);
delete new_thd;
+ /* Remember that we don't have a THD */
+ my_pthread_setspecific_ptr(THR_THD, 0);
DBUG_VOID_RETURN;
}
diff --git a/strings/strto.c b/strings/strto.c
index 84dccbcbeb8..c98b19a7e67 100644
--- a/strings/strto.c
+++ b/strings/strto.c
@@ -103,6 +103,7 @@ function (const char *nptr,char **endptr,int base)
}
/* Check for a sign. */
+ negative= 0;
if (*s == '-')
{
negative = 1;
@@ -110,11 +111,9 @@ function (const char *nptr,char **endptr,int base)
}
else if (*s == '+')
{
- negative = 0;
++s;
}
- else
- negative = 0;
+
if (base == 16 && s[0] == '0' && toupper (s[1]) == 'X')
s += 2;