summaryrefslogtreecommitdiff
path: root/sql/sql_class.h
diff options
context:
space:
mode:
authorunknown <kostja@bodhi.local>2006-07-13 11:43:52 +0400
committerunknown <kostja@bodhi.local>2006-07-13 11:43:52 +0400
commitd013f9e53ac855c15279385489660dbe15cb0ec2 (patch)
tree89fcc7cfa6078548d86b4bbdc2e9d98f72755958 /sql/sql_class.h
parent26f0d13d0163beba2ae4f96396302b0c44407c65 (diff)
parenta4e5d04db42bf492e2dc3af1ad11bc883959f50d (diff)
downloadmariadb-git-d013f9e53ac855c15279385489660dbe15cb0ec2.tar.gz
Merge bodhi.local:/opt/local/work/tmp_merge
into bodhi.local:/opt/local/work/mysql-5.1-runtime-merge-5.0 include/my_sys.h: Auto merged mysql-test/r/auto_increment.result: Auto merged mysql-test/r/func_math.result: Auto merged mysql-test/r/func_system.result: Auto merged mysql-test/r/func_time.result: Auto merged mysql-test/r/information_schema.result: Auto merged mysql-test/r/query_cache.result: Auto merged mysql-test/r/subselect.result: Auto merged mysql-test/r/trigger.result: Auto merged mysql-test/r/type_blob.result: Auto merged mysql-test/r/variables.result: Auto merged mysql-test/r/view.result: Auto merged mysql-test/t/trigger.test: Auto merged sql/ha_ndbcluster.cc: Auto merged sql/log.cc: Auto merged sql/slave.cc: Auto merged sql/sql_lex.cc: Auto merged sql/sql_lex.h: Auto merged sql/sql_select.cc: Auto merged sql/sql_trigger.cc: Auto merged sql/sql_yacc.yy: Auto merged storage/ndb/src/kernel/blocks/dbdict/Dbdict.hpp: Auto merged storage/ndb/src/mgmsrv/ConfigInfo.cpp: Auto merged sql/slave.h: SCCS merged mysql-test/r/show_check.result: Manual merge. mysql-test/t/show_check.test: Manual merge. sql/log_event.cc: Manual merge. sql/share/errmsg.txt: Manual merge. sql/sql_class.h: Manual merge. sql/sql_db.cc: Manual merge.
Diffstat (limited to 'sql/sql_class.h')
-rw-r--r--sql/sql_class.h16
1 files changed, 12 insertions, 4 deletions
diff --git a/sql/sql_class.h b/sql/sql_class.h
index c7a3738c076..6a8c901b2b3 100644
--- a/sql/sql_class.h
+++ b/sql/sql_class.h
@@ -1576,21 +1576,29 @@ public:
/*
Initialize the current database from a NULL-terminated string with length
+ If we run out of memory, we free the current database and return TRUE.
+ This way the user will notice the error as there will be no current
+ database selected (in addition to the error message set by malloc).
*/
- void set_db(const char *new_db, uint new_db_len)
+ bool set_db(const char *new_db, uint new_db_len)
{
- if (new_db)
+ /* Do not reallocate memory if current chunk is big enough. */
+ if (db && new_db && db_length >= new_db_len)
+ memcpy(db, new_db, new_db_len+1);
+ else
{
/* Do not reallocate memory if current chunk is big enough. */
if (db && db_length >= new_db_len)
memcpy(db, new_db, new_db_len+1);
else
{
- safeFree(db);
- db= my_strndup(new_db, new_db_len, MYF(MY_WME));
+ x_free(db);
+ db= new_db ? my_strndup(new_db, new_db_len, MYF(MY_WME)) : NULL;
}
db_length= db ? new_db_len: 0;
}
+ db_length= db ? new_db_len : 0;
+ return new_db && !db;
}
void reset_db(char *new_db, uint new_db_len)
{