Commit 591b0585 authored by unknown's avatar unknown

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
parent 7280bddb
...@@ -19,7 +19,7 @@ TZ=GMT-3; export TZ # for UNIX_TIMESTAMP tests to work ...@@ -19,7 +19,7 @@ TZ=GMT-3; export TZ # for UNIX_TIMESTAMP tests to work
# Program Definitions # 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" MASTER_40_ARGS="--rpl-recovery-rank=1 --init-rpl-role=master"
# Standard functions # Standard functions
...@@ -47,13 +47,17 @@ which () ...@@ -47,13 +47,17 @@ which ()
sleep_until_file_deleted () sleep_until_file_deleted ()
{ {
file=$1 pid=$1;
file=$2
loop=$SLEEP_TIME_FOR_DELETE loop=$SLEEP_TIME_FOR_DELETE
while (test $loop -gt 0) while (test $loop -gt 0)
do do
if [ ! -r $file ] if [ ! -r $file ]
then then
sleep $SLEEP_TIME_AFTER_RESTART if test $pid != "0"
then
wait_for_pid $pid
fi
return return
fi fi
sleep 1 sleep 1
...@@ -79,6 +83,13 @@ sleep_until_file_created () ...@@ -79,6 +83,13 @@ sleep_until_file_created ()
exit 1; exit 1;
} }
# For the future
wait_for_pid()
{
pid=$1
}
# No paths below as we can't be sure where the program is! # No paths below as we can't be sure where the program is!
SED=sed SED=sed
...@@ -152,6 +163,7 @@ TOT_TEST=0 ...@@ -152,6 +163,7 @@ TOT_TEST=0
USERT=0 USERT=0
SYST=0 SYST=0
REALT=0 REALT=0
FAST_START=""
MYSQL_TMP_DIR=$MYSQL_TEST_DIR/var/tmp MYSQL_TMP_DIR=$MYSQL_TEST_DIR/var/tmp
SLAVE_LOAD_TMPDIR=../../var/tmp #needs to be same length to test logging SLAVE_LOAD_TMPDIR=../../var/tmp #needs to be same length to test logging
RES_SPACE=" " RES_SPACE=" "
...@@ -314,7 +326,7 @@ while test $# -gt 0; do ...@@ -314,7 +326,7 @@ while test $# -gt 0; do
VALGRIND="valgrind --alignment=8 --leak-check=yes" VALGRIND="valgrind --alignment=8 --leak-check=yes"
EXTRA_MASTER_MYSQLD_OPT="$EXTRA_MASTER_MYSQLD_OPT --skip-safemalloc" EXTRA_MASTER_MYSQLD_OPT="$EXTRA_MASTER_MYSQLD_OPT --skip-safemalloc"
EXTRA_SLAVE_MYSQLD_OPT="$EXTRA_SLAVE_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 SLEEP_TIME_FOR_DELETE=120
;; ;;
--valgrind-options=*) --valgrind-options=*)
...@@ -335,6 +347,9 @@ while test $# -gt 0; do ...@@ -335,6 +347,9 @@ while test $# -gt 0; do
--debug=d:t:i:O,$MYSQL_TEST_DIR/var/log/slave.trace" --debug=d:t:i:O,$MYSQL_TEST_DIR/var/log/slave.trace"
EXTRA_MYSQL_TEST_OPT="$EXTRA_MYSQL_TEST_OPT --debug" EXTRA_MYSQL_TEST_OPT="$EXTRA_MYSQL_TEST_OPT --debug"
;; ;;
--fast)
FAST_START=1
;;
-- ) shift; break ;; -- ) shift; break ;;
--* ) $ECHO "Unrecognized option: $1"; exit 1 ;; --* ) $ECHO "Unrecognized option: $1"; exit 1 ;;
* ) break ;; * ) break ;;
...@@ -731,12 +746,19 @@ EOF ...@@ -731,12 +746,19 @@ EOF
manager_term() manager_term()
{ {
ident=$1 pid=$1
ident=$2
shift shift
if [ $USE_MANAGER = 0 ] ; then if [ $USE_MANAGER = 0 ] ; then
$MYSQLADMIN --no-defaults -uroot --socket=$MYSQL_TMP_DIR/$ident.sock -O \ $MYSQLADMIN --no-defaults -uroot --socket=$MYSQL_TMP_DIR/$ident.sock --connect_timeout=5 --shutdown_timeout=20 shutdown >> $MYSQL_MANAGER_LOG 2>&1
connect_timeout=5 -O shutdown_timeout=20 shutdown >> $MYSQL_MANAGER_LOG 2>&1 res=$?
return # 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 fi
$MYSQL_MANAGER_CLIENT $MANAGER_QUIET_OPT --user=$MYSQL_MANAGER_USER \ $MYSQL_MANAGER_CLIENT $MANAGER_QUIET_OPT --user=$MYSQL_MANAGER_USER \
--password=$MYSQL_MANAGER_PW --port=$MYSQL_MANAGER_PORT <<EOF --password=$MYSQL_MANAGER_PW --port=$MYSQL_MANAGER_PORT <<EOF
...@@ -978,12 +1000,13 @@ stop_slave () ...@@ -978,12 +1000,13 @@ stop_slave ()
fi fi
if [ x$this_slave_running = x1 ] if [ x$this_slave_running = x1 ]
then then
manager_term $slave_ident pid=`$CAT $slave_pid`
manager_term $pid $slave_ident
if [ $? != 0 ] && [ -f $slave_pid ] if [ $? != 0 ] && [ -f $slave_pid ]
then # try harder! then # try harder!
$ECHO "slave not cooperating with mysqladmin, will try manual kill" $ECHO "slave not cooperating with mysqladmin, will try manual kill"
kill `$CAT $slave_pid` kill $pid
sleep_until_file_deleted $slave_pid sleep_until_file_deleted $pid $slave_pid
if [ -f $slave_pid ] ; then if [ -f $slave_pid ] ; then
$ECHO "slave refused to die. Sending SIGKILL" $ECHO "slave refused to die. Sending SIGKILL"
kill -9 `$CAT $slave_pid` kill -9 `$CAT $slave_pid`
...@@ -1002,12 +1025,13 @@ stop_master () ...@@ -1002,12 +1025,13 @@ stop_master ()
{ {
if [ x$MASTER_RUNNING = x1 ] if [ x$MASTER_RUNNING = x1 ]
then then
manager_term master pid=`$CAT $MASTER_MYPID`
manager_term $pid master
if [ $? != 0 ] && [ -f $MASTER_MYPID ] if [ $? != 0 ] && [ -f $MASTER_MYPID ]
then # try harder! then # try harder!
$ECHO "master not cooperating with mysqladmin, will try manual kill" $ECHO "master not cooperating with mysqladmin, will try manual kill"
kill `$CAT $MASTER_MYPID` kill $pid
sleep_until_file_deleted $MASTER_MYPID sleep_until_file_deleted $pid $MASTER_MYPID
if [ -f $MASTER_MYPID ] ; then if [ -f $MASTER_MYPID ] ; then
$ECHO "master refused to die. Sending SIGKILL" $ECHO "master refused to die. Sending SIGKILL"
kill -9 `$CAT $MASTER_MYPID` kill -9 `$CAT $MASTER_MYPID`
...@@ -1228,14 +1252,19 @@ run_testcase () ...@@ -1228,14 +1252,19 @@ run_testcase ()
if [ -z "$USE_RUNNING_SERVER" ] if [ -z "$USE_RUNNING_SERVER" ]
then then
if [ -z "$FAST_START" ]
then
# Ensure that no old mysqld test servers are running # 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=$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 --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=$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=$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 $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 0 $MASTER_MYPID
sleep_until_file_deleted $SLAVE_MYPID sleep_until_file_deleted 0 $SLAVE_MYPID
else
rm $MASTER_MYPID $SLAVE_MYPID
fi
# Kill any running managers # Kill any running managers
if [ -f "$MANAGER_PID_FILE" ] if [ -f "$MANAGER_PID_FILE" ]
......
drop table if exists t1; drop table if exists t1,t2;
create table t1 ( create table t1 (
col1 int not null auto_increment primary key, col1 int not null auto_increment primary key,
col2 varchar(30) not null, col2 varchar(30) not null,
......
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
# Test of alter table # Test of alter table
# #
drop table if exists t1; drop table if exists t1,t2;
create table t1 ( create table t1 (
col1 int not null auto_increment primary key, col1 int not null auto_increment primary key,
col2 varchar(30) not null, col2 varchar(30) not null,
......
...@@ -1491,12 +1491,14 @@ void Field_medium::sql_type(String &res) const ...@@ -1491,12 +1491,14 @@ void Field_medium::sql_type(String &res) const
void Field_long::store(const char *from,uint len) void Field_long::store(const char *from,uint len)
{ {
char *end;
while (len && isspace(*from)) while (len && isspace(*from))
{ {
len--; from++; len--; from++;
} }
long tmp; long tmp;
String tmp_str(from,len); String tmp_str(from,len);
from= tmp_str.c_ptr(); // Add end null if needed
errno=0; errno=0;
if (unsigned_flag) if (unsigned_flag)
{ {
...@@ -1506,11 +1508,13 @@ void Field_long::store(const char *from,uint len) ...@@ -1506,11 +1508,13 @@ void Field_long::store(const char *from,uint len)
errno=ERANGE; errno=ERANGE;
} }
else else
tmp=(long) strtoul(tmp_str.c_ptr(),NULL,10); tmp=(long) strtoul(from, &end, 10);
} }
else else
tmp=strtol(tmp_str.c_ptr(),NULL,10); tmp=strtol(from, &end, 10);
if (errno || current_thd->count_cuted_fields && !test_if_int(from,len)) if (errno ||
(from+len != end && current_thd->count_cuted_fields &&
!test_if_int(from,len)))
current_thd->cuted_fields++; current_thd->cuted_fields++;
#ifdef WORDS_BIGENDIAN #ifdef WORDS_BIGENDIAN
if (table->db_low_byte_first) if (table->db_low_byte_first)
...@@ -1719,12 +1723,14 @@ void Field_long::sql_type(String &res) const ...@@ -1719,12 +1723,14 @@ void Field_long::sql_type(String &res) const
void Field_longlong::store(const char *from,uint len) void Field_longlong::store(const char *from,uint len)
{ {
char *end;
while (len && isspace(*from)) while (len && isspace(*from))
{ // For easy error check { // For easy error check
len--; from++; len--; from++;
} }
longlong tmp; longlong tmp;
String tmp_str(from,len); String tmp_str(from,len);
from= tmp_str.c_ptr(); // Add end null if needed
errno=0; errno=0;
if (unsigned_flag) if (unsigned_flag)
{ {
...@@ -1734,11 +1740,13 @@ void Field_longlong::store(const char *from,uint len) ...@@ -1734,11 +1740,13 @@ void Field_longlong::store(const char *from,uint len)
errno=ERANGE; errno=ERANGE;
} }
else else
tmp=(longlong) strtoull(tmp_str.c_ptr(),NULL,10); tmp=(longlong) strtoull(from, &end, 10);
} }
else else
tmp=strtoll(tmp_str.c_ptr(),NULL,10); tmp=strtoll(from, &end, 10);
if (errno || current_thd->count_cuted_fields && !test_if_int(from,len)) if (errno ||
(from+len != end && current_thd->count_cuted_fields &&
!test_if_int(from,len)))
current_thd->cuted_fields++; current_thd->cuted_fields++;
#ifdef WORDS_BIGENDIAN #ifdef WORDS_BIGENDIAN
if (table->db_low_byte_first) if (table->db_low_byte_first)
......
...@@ -674,36 +674,6 @@ innobase_init(void) ...@@ -674,36 +674,6 @@ innobase_init(void)
/* Set InnoDB initialization parameters according to the values /* Set InnoDB initialization parameters according to the values
read from MySQL .cnf file */ 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 -------------------------*/ /*--------------- Data files -------------------------*/
/* The default dir for data files is the datadir of MySQL */ /* The default dir for data files is the datadir of MySQL */
......
...@@ -1053,41 +1053,45 @@ bool MYSQL_LOG::write(Log_event* event_info) ...@@ -1053,41 +1053,45 @@ bool MYSQL_LOG::write(Log_event* event_info)
No check for auto events flag here - this write method should No check for auto events flag here - this write method should
never be called if auto-events are enabled never be called if auto-events are enabled
*/ */
if (thd && thd->last_insert_id_used) if (thd)
{
if (thd->last_insert_id_used)
{ {
Intvar_log_event e(thd,(uchar)LAST_INSERT_ID_EVENT,thd->last_insert_id); Intvar_log_event e(thd,(uchar) LAST_INSERT_ID_EVENT,
thd->last_insert_id);
e.set_log_pos(this); e.set_log_pos(this);
if (thd->server_id) if (thd->server_id)
e.server_id = thd->server_id; e.server_id = thd->server_id;
if (e.write(file)) if (e.write(file))
goto err; goto err;
} }
if (thd && thd->insert_id_used) if (thd->insert_id_used)
{ {
Intvar_log_event e(thd,(uchar)INSERT_ID_EVENT,thd->last_insert_id); Intvar_log_event e(thd,(uchar) INSERT_ID_EVENT,thd->last_insert_id);
e.set_log_pos(this); e.set_log_pos(this);
if (thd->server_id) if (thd->server_id)
e.server_id = thd->server_id; e.server_id = thd->server_id;
if (e.write(file)) if (e.write(file))
goto err; goto err;
} }
if (thd && thd->rand_used) if (thd->rand_used)
{ {
Rand_log_event e(thd,thd->rand_saved_seed1,thd->rand_saved_seed2); Rand_log_event e(thd,thd->rand_saved_seed1,thd->rand_saved_seed2);
e.set_log_pos(this); e.set_log_pos(this);
if (e.write(file)) if (e.write(file))
goto err; goto err;
} }
if (thd && thd->variables.convert_set) if (thd->variables.convert_set)
{ {
char buf[1024] = "SET CHARACTER SET "; char buf[256], *p;
char* p = strend(buf); p= strmov(strmov(buf, "SET CHARACTER SET "),
p = strmov(p, thd->variables.convert_set->name); thd->variables.convert_set->name);
Query_log_event e(thd, buf, (ulong)(p - buf), 0); Query_log_event e(thd, buf, (ulong) (p - buf), 0);
e.set_log_pos(this); e.set_log_pos(this);
if (e.write(file)) if (e.write(file))
goto err; goto err;
} }
}
event_info->set_log_pos(this); event_info->set_log_pos(this);
if (event_info->write(file) || if (event_info->write(file) ||
file == &log_file && flush_io_cache(file)) file == &log_file && flush_io_cache(file))
......
...@@ -689,6 +689,7 @@ extern String empty_string; ...@@ -689,6 +689,7 @@ extern String empty_string;
extern SHOW_VAR init_vars[],status_vars[], internal_vars[]; extern SHOW_VAR init_vars[],status_vars[], internal_vars[];
extern struct system_variables global_system_variables; extern struct system_variables global_system_variables;
extern struct system_variables max_system_variables; extern struct system_variables max_system_variables;
extern struct rand_struct sql_rand;
/* optional things, have_* variables */ /* optional things, have_* variables */
......
...@@ -32,6 +32,7 @@ ...@@ -32,6 +32,7 @@
#include <nisam.h> #include <nisam.h>
#include <thr_alarm.h> #include <thr_alarm.h>
#include <ft_global.h> #include <ft_global.h>
#include <assert.h>
#ifndef DBUG_OFF #ifndef DBUG_OFF
#define ONE_THREAD #define ONE_THREAD
...@@ -2091,6 +2092,7 @@ int main(int argc, char **argv) ...@@ -2091,6 +2092,7 @@ int main(int argc, char **argv)
(void) grant_init((THD*) 0); (void) grant_init((THD*) 0);
init_max_user_conn(); init_max_user_conn();
init_update_queries(); init_update_queries();
DBUG_ASSERT(current_thd == 0);
#ifdef HAVE_DLOPEN #ifdef HAVE_DLOPEN
if (!opt_noacl) if (!opt_noacl)
...@@ -2099,6 +2101,7 @@ int main(int argc, char **argv) ...@@ -2099,6 +2101,7 @@ int main(int argc, char **argv)
/* init_slave() must be called after the thread keys are created */ /* init_slave() must be called after the thread keys are created */
init_slave(); init_slave();
DBUG_ASSERT(current_thd == 0);
if (opt_bin_log && !server_id) if (opt_bin_log && !server_id)
{ {
server_id= !master_host ? 1 : 2; server_id= !master_host ? 1 : 2;
......
...@@ -37,7 +37,6 @@ ...@@ -37,7 +37,6 @@
#include <mysys_err.h> #include <mysys_err.h>
#include <assert.h> #include <assert.h>
extern struct rand_struct sql_rand;
/***************************************************************************** /*****************************************************************************
** Instansiate templates ** Instansiate templates
...@@ -159,7 +158,7 @@ THD::THD():user_time(0),fatal_error(0),last_insert_id_used(0), ...@@ -159,7 +158,7 @@ THD::THD():user_time(0),fatal_error(0),last_insert_id_used(0),
pthread_mutex_lock(&LOCK_thread_count); pthread_mutex_lock(&LOCK_thread_count);
ulong tmp=(ulong) (rnd(&sql_rand) * 3000000); ulong tmp=(ulong) (rnd(&sql_rand) * 3000000);
pthread_mutex_unlock(&LOCK_thread_count); 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);
} }
} }
......
...@@ -202,6 +202,8 @@ void udf_init() ...@@ -202,6 +202,8 @@ void udf_init()
new_thd->version--; // Force close to free memory new_thd->version--; // Force close to free memory
close_thread_tables(new_thd); close_thread_tables(new_thd);
delete new_thd; delete new_thd;
/* Remember that we don't have a THD */
my_pthread_setspecific_ptr(THR_THD, 0);
DBUG_VOID_RETURN; DBUG_VOID_RETURN;
} }
......
...@@ -103,6 +103,7 @@ function (const char *nptr,char **endptr,int base) ...@@ -103,6 +103,7 @@ function (const char *nptr,char **endptr,int base)
} }
/* Check for a sign. */ /* Check for a sign. */
negative= 0;
if (*s == '-') if (*s == '-')
{ {
negative = 1; negative = 1;
...@@ -110,11 +111,9 @@ function (const char *nptr,char **endptr,int base) ...@@ -110,11 +111,9 @@ function (const char *nptr,char **endptr,int base)
} }
else if (*s == '+') else if (*s == '+')
{ {
negative = 0;
++s; ++s;
} }
else
negative = 0;
if (base == 16 && s[0] == '0' && toupper (s[1]) == 'X') if (base == 16 && s[0] == '0' && toupper (s[1]) == 'X')
s += 2; s += 2;
......
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