Skip to content

Commit 9a60e89

Browse files
committed
Fixed some possible usage of freed memory
- Create_tmp_table::finalize didn't clear file after delete which could cause a double free. This is however not a likely problem as this code path is very unlikely to happen - free_tmp_table() could do handler calls even if the table was never opened. Fixed by adding a test if the table is opened.
1 parent 76b58c2 commit 9a60e89

File tree

1 file changed

+9
-5
lines changed

1 file changed

+9
-5
lines changed

sql/sql_select.cc

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18675,6 +18675,7 @@ bool Create_tmp_table::finalize(THD *thd,
1867518675
if (table->file->set_ha_share_ref(&share->ha_share))
1867618676
{
1867718677
delete table->file;
18678+
table->file= 0;
1867818679
goto err;
1867918680
}
1868018681
table->file->set_table(table);
@@ -19913,11 +19914,14 @@ free_tmp_table(THD *thd, TABLE *entry)
1991319914

1991419915
if (entry->file && entry->is_created())
1991519916
{
19916-
DBUG_ASSERT(entry->db_stat);
19917-
entry->file->ha_index_or_rnd_end();
19918-
entry->file->info(HA_STATUS_VARIABLE);
19919-
thd->tmp_tables_size+= (entry->file->stats.data_file_length +
19920-
entry->file->stats.index_file_length);
19917+
if (entry->db_stat)
19918+
{
19919+
/* The table was properly opened in open_tmp_table() */
19920+
entry->file->ha_index_or_rnd_end();
19921+
entry->file->info(HA_STATUS_VARIABLE);
19922+
thd->tmp_tables_size+= (entry->file->stats.data_file_length +
19923+
entry->file->stats.index_file_length);
19924+
}
1992119925
entry->file->ha_drop_table(entry->s->path.str);
1992219926
delete entry->file;
1992319927
}

0 commit comments

Comments
 (0)