-
manual merge of 5.0 patch and fixing an issue with closing temp tables when no binlog or RBR. Note, that despite temporary_tables is indeed double-linked list in 5.1 (patch for bug #19881) it is still enough to use only 'next' reference, as it was done for 5.0, when the list is sorted and destoyed after.
774de06d