summaryrefslogtreecommitdiff
path: root/sql
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 /sql
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
Diffstat (limited to 'sql')
-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
7 files changed, 59 insertions, 72 deletions
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;
}