diff --git a/storage/innobase/row/row0merge.c b/storage/innobase/row/row0merge.c
index a5bc6902983622ade95ea9347a57ec7f59c6db50..1b3293bf62faa5a8610d65b50cbc18b2a10cef14 100644
--- a/storage/innobase/row/row0merge.c
+++ b/storage/innobase/row/row0merge.c
@@ -2120,9 +2120,12 @@ row_merge_drop_temp_indexes(void)
 
 		if (table) {
 			dict_index_t*	index;
+			dict_index_t*	next_index;
 
 			for (index = dict_table_get_first_index(table);
-			     index; index = dict_table_get_next_index(index)) {
+			     index; index = next_index) {
+
+				next_index = dict_table_get_next_index(index);
 
 				if (*index->name == TEMP_INDEX_PREFIX) {
 					row_merge_drop_index(index, table, trx);