summaryrefslogtreecommitdiff
path: root/sql
diff options
context:
space:
mode:
authorunknown <monty@mysql.com>2005-09-22 03:23:07 +0300
committerunknown <monty@mysql.com>2005-09-22 03:23:07 +0300
commit7d6d4c8355a5a532de73156ae5e3b0b106f12cb7 (patch)
tree33776d264017bbe56f0deca483d75143bed9762a /sql
parent813fc4104efc55a25458a092118cbd3b55cf870f (diff)
downloadmariadb-git-7d6d4c8355a5a532de73156ae5e3b0b106f12cb7.tar.gz
Fixed problems found by valgrind
Fixed problems in test suite where some test failed Fixed access to not initialized memory in federated Fixed access to not initialized memory when using BIT fields in internal temporary tables BitKeeper/etc/ignore: added libmysqld/sql_cursor.h mysql-test/r/information_schema.result: Change view names to 'v#' to not cause massive conflict with other tests if test dies in the middlecd mysql-test/r/information_schema_inno.result: Remove used tables at start mysql-test/r/multi_statement.result: Remove used tables at start mysql-test/r/temp_table.result: Change view names to 'v#' to not cause massive conflict with other tests if test dies in the middle mysql-test/r/type_bit.result: More tests mysql-test/t/information_schema.test: Change view names to 'v#' to not cause massive conflict with other tests if test dies in the middle mysql-test/t/information_schema_inno.test: Remove used tables at start mysql-test/t/multi_statement.test: Remove used tables at start mysql-test/t/temp_table.test: Change view names to 'v#' to not cause massive conflict with other tests if test dies in the middle mysql-test/t/type_bit.test: More tests mysql-test/valgrind.supp: Removed some valgrind warnings that isn't errors sql/ha_federated.cc: Fixed errors discovered by valgrind: - Socket was not initialized - share->scheme was deleted while there was still pointer into it from the hash sql/item_func.h: Remove access to table object from cleanup() as the table object may have been dropped earlier (In case of temporary tables or of close_thread_tables() is run before cleanup()) This fixed a bug with access to already freed memory sql/sql_base.cc: Reset variables used by fulltext sql/sql_select.cc: Fixed various problems with bit fields when used in internal temporary tables. Calculate space needed for bit fields correctly (previously we allocated more space than needed for rows in heap/myisam tables)
Diffstat (limited to 'sql')
-rw-r--r--sql/ha_federated.cc16
-rw-r--r--sql/item_func.h3
-rw-r--r--sql/sql_base.cc2
-rw-r--r--sql/sql_select.cc40
4 files changed, 41 insertions, 20 deletions
diff --git a/sql/ha_federated.cc b/sql/ha_federated.cc
index 6230fa7bb3c..6d5c5b48ab6 100644
--- a/sql/ha_federated.cc
+++ b/sql/ha_federated.cc
@@ -588,12 +588,14 @@ static int parse_url(FEDERATED_SHARE *share, TABLE *table,
DBUG_ENTER("ha_federated::parse_url");
share->port= 0;
+ share->socket= 0;
DBUG_PRINT("info", ("Length %d \n", table->s->connect_string.length));
DBUG_PRINT("info", ("String %.*s \n", table->s->connect_string.length,
table->s->connect_string.str));
- share->scheme= my_strdup_with_length(
- (const byte*)table->s->connect_string.str,
- table->s->connect_string.length+1, MYF(0));
+ share->scheme= my_strdup_with_length((const byte*)table->s->
+ connect_string.str,
+ table->s->connect_string.length,
+ MYF(0));
// Add a null for later termination of table name
share->scheme[table->s->connect_string.length]= 0;
@@ -1375,13 +1377,9 @@ static int free_share(FEDERATED_SHARE *share)
if (!--share->use_count)
{
- if (share->scheme)
- {
- my_free((gptr) share->scheme, MYF(0));
- share->scheme= 0;
- }
-
hash_delete(&federated_open_tables, (byte*) share);
+ my_free((gptr) share->scheme, MYF(MY_ALLOW_ZERO_PTR0));
+ share->scheme= 0;
thr_lock_delete(&share->lock);
VOID(pthread_mutex_destroy(&share->mutex));
my_free((gptr) share, MYF(0));
diff --git a/sql/item_func.h b/sql/item_func.h
index 019abb0c072..e23f251d4a2 100644
--- a/sql/item_func.h
+++ b/sql/item_func.h
@@ -1286,9 +1286,6 @@ public:
{
ft_handler->please->close_search(ft_handler);
ft_handler=0;
- if (join_key)
- table->file->ft_handler=0;
- table->fulltext_searched=0;
}
concat= 0;
DBUG_VOID_RETURN;
diff --git a/sql/sql_base.cc b/sql/sql_base.cc
index fb23093731a..c083aa37d06 100644
--- a/sql/sql_base.cc
+++ b/sql/sql_base.cc
@@ -1327,6 +1327,8 @@ TABLE *open_table(THD *thd, TABLE_LIST *table_list, MEM_ROOT *mem_root,
table->keys_in_use_for_query= table->s->keys_in_use;
table->insert_values= 0;
table->used_keys= table->s->keys_for_keyread;
+ table->fulltext_searched= 0;
+ table->file->ft_handler= 0;
if (table->timestamp_field)
table->timestamp_field_type= table->timestamp_field->get_auto_set_type();
table_list->updatable= 1; // It is not derived table nor non-updatable VIEW
diff --git a/sql/sql_select.cc b/sql/sql_select.cc
index e03879f0cbb..5154eb73ebe 100644
--- a/sql/sql_select.cc
+++ b/sql/sql_select.cc
@@ -7817,18 +7817,24 @@ Field *create_tmp_field(THD *thd, TABLE *table,Item *item, Item::Type type,
if (field->maybe_null && !field->field->maybe_null())
{
result= create_tmp_field_from_item(thd, item, table, NULL,
- modify_item, convert_blob_length);
+ modify_item, convert_blob_length);
*from_field= field->field;
if (result && modify_item)
- ((Item_field*)item)->result_field= result;
+ field->result_field= result;
}
- else if (table_cant_handle_bit_fields && field->field->type() == FIELD_TYPE_BIT)
+ else if (table_cant_handle_bit_fields && field->field->type() ==
+ FIELD_TYPE_BIT)
+ {
+ *from_field= field->field;
result= create_tmp_field_from_item(thd, item, table, copy_func,
modify_item, convert_blob_length);
+ if (result && modify_item)
+ field->result_field= result;
+ }
else
result= create_tmp_field_from_field(thd, (*from_field= field->field),
item->name, table,
- modify_item ? (Item_field*) item :
+ modify_item ? field :
NULL,
convert_blob_length);
if (orig_type == Item::REF_ITEM && orig_modify)
@@ -8071,7 +8077,7 @@ create_tmp_table(THD *thd,TMP_TABLE_PARAM *param,List<Item> &fields,
Field *new_field=
create_tmp_field(thd, table, arg, arg->type(), &copy_func,
tmp_from_field, group != 0,not_all_columns,
- group || distinct,
+ distinct,
param->convert_blob_length);
if (!new_field)
goto err; // Should be OOM
@@ -8082,6 +8088,8 @@ create_tmp_table(THD *thd,TMP_TABLE_PARAM *param,List<Item> &fields,
*blob_field++= (uint) (reg_field - table->field);
blob_count++;
}
+ if (new_field->type() == FIELD_TYPE_BIT)
+ total_uneven_bit_length+= new_field->field_length & 7;
new_field->field_index= (uint) (reg_field - table->field);
*(reg_field++)= new_field;
if (new_field->real_type() == MYSQL_TYPE_STRING ||
@@ -8117,12 +8125,16 @@ create_tmp_table(THD *thd,TMP_TABLE_PARAM *param,List<Item> &fields,
write rows to the temporary table.
We here distinguish between UNION and multi-table-updates by the fact
that in the later case group is set to the row pointer.
+
+ The test for item->marker == 4 is ensure we don't create a group-by
+ key over a bit field as heap tables can't handle that.
*/
Field *new_field= (param->schema_table) ?
create_tmp_field_for_schema(thd, item, table) :
create_tmp_field(thd, table, item, type, &copy_func,
tmp_from_field, group != 0,
- not_all_columns || group != 0, 0,
+ not_all_columns || group != 0,
+ item->marker == 4,
param->convert_blob_length);
if (!new_field)
@@ -8154,7 +8166,14 @@ create_tmp_table(THD *thd,TMP_TABLE_PARAM *param,List<Item> &fields,
*(reg_field++) =new_field;
}
if (!--hidden_field_count)
+ {
+ /*
+ This was the last hidden field; Remember how many hidden fields could
+ have null
+ */
hidden_null_count=null_count;
+ null_count= 0;
+ }
}
DBUG_ASSERT(field_count >= (uint) (reg_field - table->field));
field_count= (uint) (reg_field - table->field);
@@ -8189,8 +8208,8 @@ create_tmp_table(THD *thd,TMP_TABLE_PARAM *param,List<Item> &fields,
null_count++;
}
hidden_null_pack_length=(hidden_null_count+7)/8;
- null_pack_length= hidden_null_count +
- (null_count + total_uneven_bit_length + 7) / 8;
+ null_pack_length= (hidden_null_pack_length +
+ (null_count + total_uneven_bit_length + 7) / 8);
reclength+=null_pack_length;
if (!reclength)
reclength=1; // Dummy select
@@ -12161,6 +12180,11 @@ calc_group_buffer(JOIN *join,ORDER *group)
key_length+=MAX_BLOB_WIDTH; // Can't be used as a key
else if (field->type() == MYSQL_TYPE_VARCHAR)
key_length+= field->field_length + HA_KEY_BLOB_LENGTH;
+ else if (field->type() == FIELD_TYPE_BIT)
+ {
+ /* Bit is usually stored as a longlong key for group fields */
+ key_length+= 8; // Big enough
+ }
else
key_length+= field->pack_length();
}