Commit a7251634 authored by Marko Mäkelä's avatar Marko Mäkelä

MDEV-17938: ALTER TABLE error handling accesses freed memory

This regression was introduced in MDEV-11369 instant ADD COLUMN.

prepare_inplace_alter_table_dict(): Avoid dereferencing ctx->new_table
after row_create_table_for_mysql() returns a failure code, because
it will have freed the memory.
parent 1d18665e
......@@ -5018,8 +5018,10 @@ prepare_inplace_alter_table_dict(
user_table, ctx->trx);
if (ctx->need_rebuild()) {
ut_ad(!ctx->new_table->cached);
dict_mem_table_free(ctx->new_table);
if (ctx->new_table) {
ut_ad(!ctx->new_table->cached);
dict_mem_table_free(ctx->new_table);
}
ctx->new_table = ctx->old_table;
}
......@@ -5517,7 +5519,7 @@ prepare_inplace_alter_table_dict(
break;
case DB_TABLESPACE_EXISTS:
my_error(ER_TABLESPACE_EXISTS, MYF(0),
ctx->new_table->name.m_name);
altered_table->s->table_name.str);
goto new_table_failed;
case DB_DUPLICATE_KEY:
my_error(HA_ERR_TABLE_EXIST, MYF(0),
......@@ -5525,12 +5527,13 @@ prepare_inplace_alter_table_dict(
goto new_table_failed;
case DB_UNSUPPORTED:
my_error(ER_UNSUPPORTED_EXTENSION, MYF(0),
ctx->new_table->name.m_name);
altered_table->s->table_name.str);
goto new_table_failed;
default:
my_error_innodb(error, table_name, flags);
new_table_failed:
DBUG_ASSERT(ctx->trx != ctx->prebuilt->trx);
ctx->new_table = NULL;
goto new_clustered_failed;
}
......
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