• Sergey Vojtovich's avatar
    MDEV-14815 - Server crash or AddressSanitizer errors or valgrind warnings · 4ac85d6f
    Sergey Vojtovich authored
                 in thr_lock / has_old_lock upon FLUSH TABLES
    
    Explicit partition access of partitioned MEMORY table under LOCK TABLES
    may cause subsequent statements to crash the server, deadlock, trigger
    valgrind warnings or ASAN errors. Freed memory was being used due to
    incorrect cleanup.
    
    At least MyISAM and InnoDB don't seem to be affected, since their
    THR_LOCK structures don't survive FLUSH TABLES. MEMORY keeps table shared
    data (including THR_LOCK) even if there're no open instances.
    
    There's partition_info::lock_partitions bitmap, which holds bits of
    partitions allowed to be accessed after pruning. This bitmap is
    updated for each individual statement.
    
    This bitmap was abused in ha_partition::store_lock() such that when we
    need to unlock a table, locked by LOCK TABLES, only locks for partitions
    that were accessed by previous statement were released.
    
    Eventually FLUSH TABLES frees THR_LOCK_DATA objects, which are still
    linked into THR_LOCK lists. When such THR_LOCK gets reused we end up with
    freed memory access.
    
    Fixed by using ha_partition::m_locked_partitions bitmap similarly to
    ha_partition::external_lock().
    4ac85d6f
ha_partition.cc 275 KB