[MDEV-14815] Server crash or AddressSanitizer errors or valgrind warnings in thr_lock / has_old_lock upon FLUSH TABLES Created: 2017-12-29  Updated: 2018-10-19  Resolved: 2018-10-19

Status: Closed
Project: MariaDB Server
Component/s: Locking, Partitioning
Affects Version/s: 10.0, 10.1, 10.2, 10.3
Fix Version/s: 10.0.37, 10.3.11, 10.1.37, 10.2.19

Type: Bug Priority: Major
Reporter: Elena Stepanova Assignee: Sergey Vojtovich
Resolution: Fixed Votes: 0
Labels: None


 Description   

--source include/have_partition.inc
 
CREATE TABLE t1 (i INT) ENGINE=MEMORY PARTITION BY RANGE (i) (PARTITION p0 VALUES LESS THAN (4), PARTITION pm VALUES LESS THAN MAXVALUE);
LOCK TABLE t1 WRITE;
SELECT * FROM t1 PARTITION (p0);
FLUSH TABLES;
 
# Cleanup
DROP TABLE t1;

10.2 f5c479565d1d0

#3  <signal handler called>
#4  0x000055d9777b3cb3 in has_old_lock (data=0x8f8f8f8f8f8f8f8f, owner=0x7fe5ec0023f8) at /data/src/10.2/mysys/thr_lock.c:495
#5  0x000055d9777b47d8 in thr_lock (data=0x7fe5ec0fc018, owner=0x7fe5ec0023f8, lock_wait_timeout=31536000) at /data/src/10.2/mysys/thr_lock.c:943
#6  0x000055d9777b5302 in thr_multi_lock (data=0x7fe5ec1363d8, count=2, owner=0x7fe5ec0023f8, lock_wait_timeout=31536000) at /data/src/10.2/mysys/thr_lock.c:1294
#7  0x000055d977163727 in mysql_lock_tables (thd=0x7fe5ec000b00, sql_lock=0x7fe5ec1363b0, flags=2155) at /data/src/10.2/sql/lock.cc:354
#8  0x000055d977163528 in mysql_lock_tables (thd=0x7fe5ec000b00, tables=0x7fe5ec111e20, count=1, flags=2155) at /data/src/10.2/sql/lock.cc:303
#9  0x000055d976d69730 in Locked_tables_list::reopen_tables (this=0x7fe5ec004510, thd=0x7fe5ec000b00) at /data/src/10.2/sql/sql_base.cc:2389
#10 0x000055d976d65dd2 in close_cached_tables (thd=0x7fe5ec000b00, tables=0x0, wait_for_refresh=true, timeout=86400) at /data/src/10.2/sql/sql_base.cc:484
#11 0x000055d976f5887f in reload_acl_and_cache (thd=0x7fe5ec000b00, options=4, tables=0x0, write_to_binlog=0x7fe5fc297910) at /data/src/10.2/sql/sql_reload.cc:334
#12 0x000055d976de0d14 in mysql_execute_command (thd=0x7fe5ec000b00) at /data/src/10.2/sql/sql_parse.cc:5385
#13 0x000055d976de82e8 in mysql_parse (thd=0x7fe5ec000b00, rawbuf=0x7fe5ec0124e8 "FLUSH TABLES", length=12, parser_state=0x7fe5fc298200, is_com_multi=false, is_next_command=false) at /data/src/10.2/sql/sql_parse.cc:7900
#14 0x000055d976dd61f6 in dispatch_command (command=COM_QUERY, thd=0x7fe5ec000b00, packet=0x7fe5ec170451 "FLUSH TABLES", packet_length=12, is_com_multi=false, is_next_command=false) at /data/src/10.2/sql/sql_parse.cc:1805
#15 0x000055d976dd4b54 in do_command (thd=0x7fe5ec000b00) at /data/src/10.2/sql/sql_parse.cc:1360
#16 0x000055d976f22a0b in do_handle_one_connection (connect=0x55d97977d540) at /data/src/10.2/sql/sql_connect.cc:1335
#17 0x000055d976f22798 in handle_one_connection (arg=0x55d97977d540) at /data/src/10.2/sql/sql_connect.cc:1241
#18 0x000055d9773418c8 in pfs_spawn_thread (arg=0x55d9796db1f0) at /data/src/10.2/storage/perfschema/pfs.cc:1863
#19 0x00007fe603c93494 in start_thread (arg=0x7fe5fc299700) at pthread_create.c:333
#20 0x00007fe60207993f in clone () from /lib/x86_64-linux-gnu/libc.so.6

10.1 doesn't crash for me, but it fails with ASAN, for example:

10.1 ASAN 2fe6186124ab

==13075==ERROR: AddressSanitizer: heap-use-after-free on address 0x618000029fa8 at pc 0x55b7b726a950 bp 0x7fcbb9d82270 sp 0x7fcbb9d82268
READ of size 4 at 0x618000029fa8 thread T6
    #0 0x55b7b726a94f in thr_lock /data/src/10.1/mysys/thr_lock.c:897
    #1 0x55b7b726a94f in thr_multi_lock /data/src/10.1/mysys/thr_lock.c:1302
    #2 0x55b7b66c5efa in mysql_lock_tables(THD*, st_mysql_lock*, unsigned int) /data/src/10.1/sql/lock.cc:323
    #3 0x55b7b66c8d51 in mysql_lock_tables(THD*, TABLE**, unsigned int, unsigned int) /data/src/10.1/sql/lock.cc:275
    #4 0x55b7b5e373b5 in Locked_tables_list::reopen_tables(THD*) /data/src/10.1/sql/sql_base.cc:3060
    #5 0x55b7b5e37bb0 in close_cached_tables(THD*, TABLE_LIST*, bool, unsigned long) /data/src/10.1/sql/sql_base.cc:595
    #6 0x55b7b624849e in reload_acl_and_cache(THD*, unsigned long long, TABLE_LIST*, int*) /data/src/10.1/sql/sql_reload.cc:334
    #7 0x55b7b5f37ceb in mysql_execute_command(THD*) /data/src/10.1/sql/sql_parse.cc:4868
    #8 0x55b7b5f40852 in mysql_parse(THD*, char*, unsigned int, Parser_state*) /data/src/10.1/sql/sql_parse.cc:7347
    #9 0x55b7b5f47053 in dispatch_command(enum_server_command, THD*, char*, unsigned int) /data/src/10.1/sql/sql_parse.cc:1477
    #10 0x55b7b5f4d606 in do_command(THD*) /data/src/10.1/sql/sql_parse.cc:1106
    #11 0x55b7b61efa42 in do_handle_one_connection(THD*) /data/src/10.1/sql/sql_connect.cc:1330
    #12 0x55b7b61eff53 in handle_one_connection /data/src/10.1/sql/sql_connect.cc:1242
    #13 0x55b7b6ab4936 in pfs_spawn_thread /data/src/10.1/storage/perfschema/pfs.cc:1861
    #14 0x7fcbc64cf493 in start_thread (/lib/x86_64-linux-gnu/libpthread.so.0+0x7493)
    #15 0x7fcbc488893e in __clone (/lib/x86_64-linux-gnu/libc.so.6+0xe893e)
 
0x618000029fa8 is located 808 bytes inside of 852-byte region [0x618000029c80,0x618000029fd4)
freed by thread T6 here:
    #0 0x7fcbc6739527 in __interceptor_free (/usr/lib/x86_64-linux-gnu/libasan.so.1+0x54527)
    #1 0x55b7b727d6af in free_memory /data/src/10.1/mysys/safemalloc.c:276
 
previously allocated by thread T6 here:
    #0 0x7fcbc673973f in malloc (/usr/lib/x86_64-linux-gnu/libasan.so.1+0x5473f)
    #1 0x55b7b727d782 in sf_malloc /data/src/10.1/mysys/safemalloc.c:115
    #2 0x55b7b737609a (/data/bld/10.1-asan/bin/mysqld+0x1d8509a)
 
Thread T6 created by T0 here:
    #0 0x7fcbc6708bba in pthread_create (/usr/lib/x86_64-linux-gnu/libasan.so.1+0x23bba)
    #1 0x55b7b6ac018d in spawn_thread_v1 /data/src/10.1/storage/perfschema/pfs.cc:1911
 
SUMMARY: AddressSanitizer: heap-use-after-free /data/src/10.1/mysys/thr_lock.c:897 thr_lock
Shadow bytes around the buggy address:
  0x0c307fffd3a0: fd fd fd fd fd fd fd fd fd fd fd fd fd fd fd fd
  0x0c307fffd3b0: fd fd fd fd fd fd fd fd fd fd fd fd fd fd fd fd
  0x0c307fffd3c0: fd fd fd fd fd fd fd fd fd fd fd fd fd fd fd fd
  0x0c307fffd3d0: fd fd fd fd fd fd fd fd fd fd fd fd fd fd fd fd
  0x0c307fffd3e0: fd fd fd fd fd fd fd fd fd fd fd fd fd fd fd fd
=>0x0c307fffd3f0: fd fd fd fd fd[fd]fd fd fd fd fd fa fa fa fa fa
  0x0c307fffd400: fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa
  0x0c307fffd410: fd fd fd fd fd fd fd fd fd fd fd fd fd fd fd fd
  0x0c307fffd420: fd fd fd fd fd fd fd fd fd fd fd fd fd fd fd fd
  0x0c307fffd430: fd fd fd fd fd fd fd fd fd fd fd fd fd fd fd fd
  0x0c307fffd440: fd fd fd fd fd fd fd fd fd fd fd fd fd fd fd fd
Shadow byte legend (one shadow byte represents 8 application bytes):
  Addressable:           00
  Partially addressable: 01 02 03 04 05 06 07 
  Heap left redzone:       fa
  Heap right redzone:      fb
  Freed heap region:       fd
  Stack left redzone:      f1
  Stack mid redzone:       f2
  Stack right redzone:     f3
  Stack partial redzone:   f4
  Stack after return:      f5
  Stack use after scope:   f8
  Global redzone:          f9
  Global init order:       f6
  Poisoned by user:        f7
  Contiguous container OOB:fc
  ASan internal:           fe
==13075==ABORTING

10.0 also doesn't crash for me, but it fails with ASAN or Valgrind
(note, it's a quite old revision, so the problem isn't new)

10.0 1d47bd61d55e

==13153== Thread 4:
==13153== Invalid read of size 4
==13153==    at 0xE871DB: thr_lock (thr_lock.c:785)
==13153==    by 0xE87D23: thr_multi_lock (thr_lock.c:1179)
==13153==    by 0x9269AB: mysql_lock_tables(THD*, st_mysql_lock*, unsigned int) (lock.cc:321)
==13153==    by 0x9267FD: mysql_lock_tables(THD*, TABLE**, unsigned int, unsigned int) (lock.cc:275)
==13153==    by 0x5EA225: Locked_tables_list::reopen_tables(THD*) (sql_base.cc:3018)
==13153==    by 0x5E5A84: close_cached_tables(THD*, TABLE_LIST*, bool, unsigned long) (sql_base.cc:571)
==13153==    by 0x79C097: reload_acl_and_cache(THD*, unsigned long long, TABLE_LIST*, int*) (sql_reload.cc:300)
==13153==    by 0x650158: mysql_execute_command(THD*) (sql_parse.cc:4313)
==13153==    by 0x655B91: mysql_parse(THD*, char*, unsigned int, Parser_state*) (sql_parse.cc:6583)
==13153==    by 0x6486F1: dispatch_command(enum_server_command, THD*, char*, unsigned int) (sql_parse.cc:1309)
==13153==    by 0x6479B4: do_command(THD*) (sql_parse.cc:999)
==13153==    by 0x76BEBE: do_handle_one_connection(THD*) (sql_connect.cc:1377)
==13153==    by 0x76BC30: handle_one_connection (sql_connect.cc:1292)
==13153==    by 0xAE9909: pfs_spawn_thread (pfs.cc:1860)
==13153==    by 0x4E3F493: start_thread (pthread_create.c:333)
==13153==    by 0x6D3593E: clone (clone.S:97)
==13153==  Address 0xd8c8cc0 is 704 bytes inside a block of size 744 free'd
==13153==    at 0x4C2CDDB: free (vg_replace_malloc.c:530)
==13153==    by 0xE7B566: my_free (my_malloc.c:216)
==13153==    by 0xE379C3: hp_close (hp_close.c:49)
==13153==    by 0xE378B0: heap_close (hp_close.c:28)
==13153==    by 0xE2C668: ha_heap::close() (ha_heap.cc:141)
==13153==    by 0x846336: handler::ha_close() (handler.cc:2587)
==13153==    by 0xE42A02: ha_partition::close() (ha_partition.cc:3692)
==13153==    by 0x846336: handler::ha_close() (handler.cc:2587)
==13153==    by 0x72C2C1: closefrm(TABLE*, bool) (table.cc:2957)
==13153==    by 0x5E52C6: intern_close_table(TABLE*) (sql_base.cc:337)
==13153==    by 0x7D15ED: tc_release_table(TABLE*) (table_cache.cc:408)
==13153==    by 0x5E6854: close_thread_table(THD*, TABLE**) (sql_base.cc:1046)
==13153==    by 0x5E6240: close_all_tables_for_name(THD*, TABLE_SHARE*, ha_extra_function, TABLE*) (sql_base.cc:836)
==13153==    by 0x5E57E1: close_cached_tables(THD*, TABLE_LIST*, bool, unsigned long) (sql_base.cc:498)
==13153==    by 0x79C097: reload_acl_and_cache(THD*, unsigned long long, TABLE_LIST*, int*) (sql_reload.cc:300)
==13153==    by 0x650158: mysql_execute_command(THD*) (sql_parse.cc:4313)
==13153==  Block was alloc'd at
==13153==    at 0x4C2BBAF: malloc (vg_replace_malloc.c:299)
==13153==    by 0xE7B089: my_malloc (my_malloc.c:100)
==13153==    by 0xE32067: heap_open_from_share (hp_open.c:33)
==13153==    by 0xE323BF: heap_open (hp_open.c:121)
==13153==    by 0xE2C465: ha_heap::open(char const*, int, unsigned int) (ha_heap.cc:95)
==13153==    by 0x845F3D: handler::ha_open(TABLE*, char const*, int, unsigned int) (handler.cc:2525)
==13153==    by 0xE4237D: ha_partition::open(char const*, int, unsigned int) (ha_partition.cc:3492)
==13153==    by 0x845F3D: handler::ha_open(TABLE*, char const*, int, unsigned int) (handler.cc:2525)
==13153==    by 0x72BF17: open_table_from_share(THD*, TABLE_SHARE*, char const*, unsigned int, unsigned int, unsigned int, TABLE*, bool) (table.cc:2865)
==13153==    by 0x5E9449: open_table(THD*, TABLE_LIST*, st_mem_root*, Open_table_context*) (sql_base.cc:2516)
==13153==    by 0x5EBBAF: open_and_process_table(THD*, LEX*, TABLE_LIST*, unsigned int*, unsigned int, Prelocking_strategy*, bool, Open_table_context*, st_mem_root*) (sql_base.cc:4034)
==13153==    by 0x5ECC64: open_tables(THD*, TABLE_LIST**, unsigned int*, unsigned int, Prelocking_strategy*) (sql_base.cc:4568)
==13153==    by 0x64A865: lock_tables_open_and_lock_tables(THD*, TABLE_LIST*) (sql_parse.cc:2146)
==13153==    by 0x64E93E: mysql_execute_command(THD*) (sql_parse.cc:3847)
==13153==    by 0x655B91: mysql_parse(THD*, char*, unsigned int, Parser_state*) (sql_parse.cc:6583)
==13153==    by 0x6486F1: dispatch_command(enum_server_command, THD*, char*, unsigned int) (sql_parse.cc:1309)
==13153== Invalid read of size 8
==13153==    at 0xE869E8: has_old_lock (thr_lock.c:478)
==13153==    by 0xE87294: thr_lock (thr_lock.c:842)
==13153==    by 0xE87D23: thr_multi_lock (thr_lock.c:1179)
==13153==    by 0x9269AB: mysql_lock_tables(THD*, st_mysql_lock*, unsigned int) (lock.cc:321)
==13153==    by 0x9267FD: mysql_lock_tables(THD*, TABLE**, unsigned int, unsigned int) (lock.cc:275)
==13153==    by 0x5EA225: Locked_tables_list::reopen_tables(THD*) (sql_base.cc:3018)
==13153==    by 0x5E5A84: close_cached_tables(THD*, TABLE_LIST*, bool, unsigned long) (sql_base.cc:571)
==13153==    by 0x79C097: reload_acl_and_cache(THD*, unsigned long long, TABLE_LIST*, int*) (sql_reload.cc:300)
==13153==    by 0x650158: mysql_execute_command(THD*) (sql_parse.cc:4313)
==13153==    by 0x655B91: mysql_parse(THD*, char*, unsigned int, Parser_state*) (sql_parse.cc:6583)
==13153==    by 0x6486F1: dispatch_command(enum_server_command, THD*, char*, unsigned int) (sql_parse.cc:1309)
==13153==    by 0x6479B4: do_command(THD*) (sql_parse.cc:999)
==13153==    by 0x76BEBE: do_handle_one_connection(THD*) (sql_connect.cc:1377)
==13153==    by 0x76BC30: handle_one_connection (sql_connect.cc:1292)
==13153==    by 0xAE9909: pfs_spawn_thread (pfs.cc:1860)
==13153==    by 0x4E3F493: start_thread (pthread_create.c:333)
==13153==  Address 0xd8c8c80 is 640 bytes inside a block of size 744 free'd
==13153==    at 0x4C2CDDB: free (vg_replace_malloc.c:530)
==13153==    by 0xE7B566: my_free (my_malloc.c:216)
==13153==    by 0xE379C3: hp_close (hp_close.c:49)
==13153==    by 0xE378B0: heap_close (hp_close.c:28)
==13153==    by 0xE2C668: ha_heap::close() (ha_heap.cc:141)
==13153==    by 0x846336: handler::ha_close() (handler.cc:2587)
==13153==    by 0xE42A02: ha_partition::close() (ha_partition.cc:3692)
==13153==    by 0x846336: handler::ha_close() (handler.cc:2587)
==13153==    by 0x72C2C1: closefrm(TABLE*, bool) (table.cc:2957)
==13153==    by 0x5E52C6: intern_close_table(TABLE*) (sql_base.cc:337)
==13153==    by 0x7D15ED: tc_release_table(TABLE*) (table_cache.cc:408)
==13153==    by 0x5E6854: close_thread_table(THD*, TABLE**) (sql_base.cc:1046)
==13153==    by 0x5E6240: close_all_tables_for_name(THD*, TABLE_SHARE*, ha_extra_function, TABLE*) (sql_base.cc:836)
==13153==    by 0x5E57E1: close_cached_tables(THD*, TABLE_LIST*, bool, unsigned long) (sql_base.cc:498)
==13153==    by 0x79C097: reload_acl_and_cache(THD*, unsigned long long, TABLE_LIST*, int*) (sql_reload.cc:300)
==13153==    by 0x650158: mysql_execute_command(THD*) (sql_parse.cc:4313)
==13153==  Block was alloc'd at
==13153==    at 0x4C2BBAF: malloc (vg_replace_malloc.c:299)
==13153==    by 0xE7B089: my_malloc (my_malloc.c:100)
==13153==    by 0xE32067: heap_open_from_share (hp_open.c:33)
==13153==    by 0xE323BF: heap_open (hp_open.c:121)
==13153==    by 0xE2C465: ha_heap::open(char const*, int, unsigned int) (ha_heap.cc:95)
==13153==    by 0x845F3D: handler::ha_open(TABLE*, char const*, int, unsigned int) (handler.cc:2525)
==13153==    by 0xE4237D: ha_partition::open(char const*, int, unsigned int) (ha_partition.cc:3492)
==13153==    by 0x845F3D: handler::ha_open(TABLE*, char const*, int, unsigned int) (handler.cc:2525)
==13153==    by 0x72BF17: open_table_from_share(THD*, TABLE_SHARE*, char const*, unsigned int, unsigned int, unsigned int, TABLE*, bool) (table.cc:2865)
==13153==    by 0x5E9449: open_table(THD*, TABLE_LIST*, st_mem_root*, Open_table_context*) (sql_base.cc:2516)
==13153==    by 0x5EBBAF: open_and_process_table(THD*, LEX*, TABLE_LIST*, unsigned int*, unsigned int, Prelocking_strategy*, bool, Open_table_context*, st_mem_root*) (sql_base.cc:4034)
==13153==    by 0x5ECC64: open_tables(THD*, TABLE_LIST**, unsigned int*, unsigned int, Prelocking_strategy*) (sql_base.cc:4568)
==13153==    by 0x64A865: lock_tables_open_and_lock_tables(THD*, TABLE_LIST*) (sql_parse.cc:2146)
==13153==    by 0x64E93E: mysql_execute_command(THD*) (sql_parse.cc:3847)
==13153==    by 0x655B91: mysql_parse(THD*, char*, unsigned int, Parser_state*) (sql_parse.cc:6583)
==13153==    by 0x6486F1: dispatch_command(enum_server_command, THD*, char*, unsigned int) (sql_parse.cc:1309)
==13153== Invalid write of size 8
==13153==    at 0xE872AC: thr_lock (thr_lock.c:848)
==13153==    by 0xE87D23: thr_multi_lock (thr_lock.c:1179)
==13153==    by 0x9269AB: mysql_lock_tables(THD*, st_mysql_lock*, unsigned int) (lock.cc:321)
==13153==    by 0x9267FD: mysql_lock_tables(THD*, TABLE**, unsigned int, unsigned int) (lock.cc:275)
==13153==    by 0x5EA225: Locked_tables_list::reopen_tables(THD*) (sql_base.cc:3018)
==13153==    by 0x5E5A84: close_cached_tables(THD*, TABLE_LIST*, bool, unsigned long) (sql_base.cc:571)
==13153==    by 0x79C097: reload_acl_and_cache(THD*, unsigned long long, TABLE_LIST*, int*) (sql_reload.cc:300)
==13153==    by 0x650158: mysql_execute_command(THD*) (sql_parse.cc:4313)
==13153==    by 0x655B91: mysql_parse(THD*, char*, unsigned int, Parser_state*) (sql_parse.cc:6583)
==13153==    by 0x6486F1: dispatch_command(enum_server_command, THD*, char*, unsigned int) (sql_parse.cc:1309)
==13153==    by 0x6479B4: do_command(THD*) (sql_parse.cc:999)
==13153==    by 0x76BEBE: do_handle_one_connection(THD*) (sql_connect.cc:1377)
==13153==    by 0x76BC30: handle_one_connection (sql_connect.cc:1292)
==13153==    by 0xAE9909: pfs_spawn_thread (pfs.cc:1860)
==13153==    by 0x4E3F493: start_thread (pthread_create.c:333)
==13153==    by 0x6D3593E: clone (clone.S:97)
==13153==  Address 0xd8c8c88 is 648 bytes inside a block of size 744 free'd
==13153==    at 0x4C2CDDB: free (vg_replace_malloc.c:530)
==13153==    by 0xE7B566: my_free (my_malloc.c:216)
==13153==    by 0xE379C3: hp_close (hp_close.c:49)
==13153==    by 0xE378B0: heap_close (hp_close.c:28)
==13153==    by 0xE2C668: ha_heap::close() (ha_heap.cc:141)
==13153==    by 0x846336: handler::ha_close() (handler.cc:2587)
==13153==    by 0xE42A02: ha_partition::close() (ha_partition.cc:3692)
==13153==    by 0x846336: handler::ha_close() (handler.cc:2587)
==13153==    by 0x72C2C1: closefrm(TABLE*, bool) (table.cc:2957)
==13153==    by 0x5E52C6: intern_close_table(TABLE*) (sql_base.cc:337)
==13153==    by 0x7D15ED: tc_release_table(TABLE*) (table_cache.cc:408)
==13153==    by 0x5E6854: close_thread_table(THD*, TABLE**) (sql_base.cc:1046)
==13153==    by 0x5E6240: close_all_tables_for_name(THD*, TABLE_SHARE*, ha_extra_function, TABLE*) (sql_base.cc:836)
==13153==    by 0x5E57E1: close_cached_tables(THD*, TABLE_LIST*, bool, unsigned long) (sql_base.cc:498)
==13153==    by 0x79C097: reload_acl_and_cache(THD*, unsigned long long, TABLE_LIST*, int*) (sql_reload.cc:300)
==13153==    by 0x650158: mysql_execute_command(THD*) (sql_parse.cc:4313)
==13153==  Block was alloc'd at
==13153==    at 0x4C2BBAF: malloc (vg_replace_malloc.c:299)
==13153==    by 0xE7B089: my_malloc (my_malloc.c:100)
==13153==    by 0xE32067: heap_open_from_share (hp_open.c:33)
==13153==    by 0xE323BF: heap_open (hp_open.c:121)
==13153==    by 0xE2C465: ha_heap::open(char const*, int, unsigned int) (ha_heap.cc:95)
==13153==    by 0x845F3D: handler::ha_open(TABLE*, char const*, int, unsigned int) (handler.cc:2525)
==13153==    by 0xE4237D: ha_partition::open(char const*, int, unsigned int) (ha_partition.cc:3492)
==13153==    by 0x845F3D: handler::ha_open(TABLE*, char const*, int, unsigned int) (handler.cc:2525)
==13153==    by 0x72BF17: open_table_from_share(THD*, TABLE_SHARE*, char const*, unsigned int, unsigned int, unsigned int, TABLE*, bool) (table.cc:2865)
==13153==    by 0x5E9449: open_table(THD*, TABLE_LIST*, st_mem_root*, Open_table_context*) (sql_base.cc:2516)
==13153==    by 0x5EBBAF: open_and_process_table(THD*, LEX*, TABLE_LIST*, unsigned int*, unsigned int, Prelocking_strategy*, bool, Open_table_context*, st_mem_root*) (sql_base.cc:4034)
==13153==    by 0x5ECC64: open_tables(THD*, TABLE_LIST**, unsigned int*, unsigned int, Prelocking_strategy*) (sql_base.cc:4568)
==13153==    by 0x64A865: lock_tables_open_and_lock_tables(THD*, TABLE_LIST*) (sql_parse.cc:2146)
==13153==    by 0x64E93E: mysql_execute_command(THD*) (sql_parse.cc:3847)
==13153==    by 0x655B91: mysql_parse(THD*, char*, unsigned int, Parser_state*) (sql_parse.cc:6583)
==13153==    by 0x6486F1: dispatch_command(enum_server_command, THD*, char*, unsigned int) (sql_parse.cc:1309)
==13153== Invalid write of size 8
==13153==    at 0xE8767F: thr_unlock (thr_lock.c:972)
==13153==    by 0xE880BC: thr_multi_unlock (thr_lock.c:1300)
==13153==    by 0x926CF2: mysql_unlock_tables(THD*, st_mysql_lock*, bool) (lock.cc:386)
==13153==    by 0x926D6B: mysql_unlock_some_tables(THD*, TABLE**, unsigned int) (lock.cc:402)
==13153==    by 0x927075: mysql_lock_remove(THD*, st_mysql_lock*, TABLE*) (lock.cc:497)
==13153==    by 0x5E622A: close_all_tables_for_name(THD*, TABLE_SHARE*, ha_extra_function, TABLE*) (sql_base.cc:835)
==13153==    by 0x6F4CFF: mysql_rm_table_no_locks(THD*, TABLE_LIST*, bool, bool, bool, bool, bool) (sql_table.cc:2477)
==13153==    by 0x6F414D: mysql_rm_table(THD*, TABLE_LIST*, char, char) (sql_table.cc:2106)
==13153==    by 0x64E2E5: mysql_execute_command(THD*) (sql_parse.cc:3704)
==13153==    by 0x655B91: mysql_parse(THD*, char*, unsigned int, Parser_state*) (sql_parse.cc:6583)
==13153==    by 0x6486F1: dispatch_command(enum_server_command, THD*, char*, unsigned int) (sql_parse.cc:1309)
==13153==    by 0x6479B4: do_command(THD*) (sql_parse.cc:999)
==13153==    by 0x76BEBE: do_handle_one_connection(THD*) (sql_connect.cc:1377)
==13153==    by 0x76BC30: handle_one_connection (sql_connect.cc:1292)
==13153==    by 0xAE9909: pfs_spawn_thread (pfs.cc:1860)
==13153==    by 0x4E3F493: start_thread (pthread_create.c:333)
==13153==  Address 0xd8c8c88 is 648 bytes inside a block of size 744 free'd
==13153==    at 0x4C2CDDB: free (vg_replace_malloc.c:530)
==13153==    by 0xE7B566: my_free (my_malloc.c:216)
==13153==    by 0xE379C3: hp_close (hp_close.c:49)
==13153==    by 0xE378B0: heap_close (hp_close.c:28)
==13153==    by 0xE2C668: ha_heap::close() (ha_heap.cc:141)
==13153==    by 0x846336: handler::ha_close() (handler.cc:2587)
==13153==    by 0xE42A02: ha_partition::close() (ha_partition.cc:3692)
==13153==    by 0x846336: handler::ha_close() (handler.cc:2587)
==13153==    by 0x72C2C1: closefrm(TABLE*, bool) (table.cc:2957)
==13153==    by 0x5E52C6: intern_close_table(TABLE*) (sql_base.cc:337)
==13153==    by 0x7D15ED: tc_release_table(TABLE*) (table_cache.cc:408)
==13153==    by 0x5E6854: close_thread_table(THD*, TABLE**) (sql_base.cc:1046)
==13153==    by 0x5E6240: close_all_tables_for_name(THD*, TABLE_SHARE*, ha_extra_function, TABLE*) (sql_base.cc:836)
==13153==    by 0x5E57E1: close_cached_tables(THD*, TABLE_LIST*, bool, unsigned long) (sql_base.cc:498)
==13153==    by 0x79C097: reload_acl_and_cache(THD*, unsigned long long, TABLE_LIST*, int*) (sql_reload.cc:300)
==13153==    by 0x650158: mysql_execute_command(THD*) (sql_parse.cc:4313)
==13153==  Block was alloc'd at
==13153==    at 0x4C2BBAF: malloc (vg_replace_malloc.c:299)
==13153==    by 0xE7B089: my_malloc (my_malloc.c:100)
==13153==    by 0xE32067: heap_open_from_share (hp_open.c:33)
==13153==    by 0xE323BF: heap_open (hp_open.c:121)
==13153==    by 0xE2C465: ha_heap::open(char const*, int, unsigned int) (ha_heap.cc:95)
==13153==    by 0x845F3D: handler::ha_open(TABLE*, char const*, int, unsigned int) (handler.cc:2525)
==13153==    by 0xE4237D: ha_partition::open(char const*, int, unsigned int) (ha_partition.cc:3492)
==13153==    by 0x845F3D: handler::ha_open(TABLE*, char const*, int, unsigned int) (handler.cc:2525)
==13153==    by 0x72BF17: open_table_from_share(THD*, TABLE_SHARE*, char const*, unsigned int, unsigned int, unsigned int, TABLE*, bool) (table.cc:2865)
==13153==    by 0x5E9449: open_table(THD*, TABLE_LIST*, st_mem_root*, Open_table_context*) (sql_base.cc:2516)
==13153==    by 0x5EBBAF: open_and_process_table(THD*, LEX*, TABLE_LIST*, unsigned int*, unsigned int, Prelocking_strategy*, bool, Open_table_context*, st_mem_root*) (sql_base.cc:4034)
==13153==    by 0x5ECC64: open_tables(THD*, TABLE_LIST**, unsigned int*, unsigned int, Prelocking_strategy*) (sql_base.cc:4568)
==13153==    by 0x64A865: lock_tables_open_and_lock_tables(THD*, TABLE_LIST*) (sql_parse.cc:2146)
==13153==    by 0x64E93E: mysql_execute_command(THD*) (sql_parse.cc:3847)
==13153==    by 0x655B91: mysql_parse(THD*, char*, unsigned int, Parser_state*) (sql_parse.cc:6583)
==13153==    by 0x6486F1: dispatch_command(enum_server_command, THD*, char*, unsigned int) (sql_parse.cc:1309)
==13153== Invalid read of size 8
==13153==    at 0xE87682: thr_unlock (thr_lock.c:972)
==13153==    by 0xE880BC: thr_multi_unlock (thr_lock.c:1300)
==13153==    by 0x926CF2: mysql_unlock_tables(THD*, st_mysql_lock*, bool) (lock.cc:386)
==13153==    by 0x926D6B: mysql_unlock_some_tables(THD*, TABLE**, unsigned int) (lock.cc:402)
==13153==    by 0x927075: mysql_lock_remove(THD*, st_mysql_lock*, TABLE*) (lock.cc:497)
==13153==    by 0x5E622A: close_all_tables_for_name(THD*, TABLE_SHARE*, ha_extra_function, TABLE*) (sql_base.cc:835)
==13153==    by 0x6F4CFF: mysql_rm_table_no_locks(THD*, TABLE_LIST*, bool, bool, bool, bool, bool) (sql_table.cc:2477)
==13153==    by 0x6F414D: mysql_rm_table(THD*, TABLE_LIST*, char, char) (sql_table.cc:2106)
==13153==    by 0x64E2E5: mysql_execute_command(THD*) (sql_parse.cc:3704)
==13153==    by 0x655B91: mysql_parse(THD*, char*, unsigned int, Parser_state*) (sql_parse.cc:6583)
==13153==    by 0x6486F1: dispatch_command(enum_server_command, THD*, char*, unsigned int) (sql_parse.cc:1309)
==13153==    by 0x6479B4: do_command(THD*) (sql_parse.cc:999)
==13153==    by 0x76BEBE: do_handle_one_connection(THD*) (sql_connect.cc:1377)
==13153==    by 0x76BC30: handle_one_connection (sql_connect.cc:1292)
==13153==    by 0xAE9909: pfs_spawn_thread (pfs.cc:1860)
==13153==    by 0x4E3F493: start_thread (pthread_create.c:333)
==13153==  Address 0xd8c8c88 is 648 bytes inside a block of size 744 free'd
==13153==    at 0x4C2CDDB: free (vg_replace_malloc.c:530)
==13153==    by 0xE7B566: my_free (my_malloc.c:216)
==13153==    by 0xE379C3: hp_close (hp_close.c:49)
==13153==    by 0xE378B0: heap_close (hp_close.c:28)
==13153==    by 0xE2C668: ha_heap::close() (ha_heap.cc:141)
==13153==    by 0x846336: handler::ha_close() (handler.cc:2587)
==13153==    by 0xE42A02: ha_partition::close() (ha_partition.cc:3692)
==13153==    by 0x846336: handler::ha_close() (handler.cc:2587)
==13153==    by 0x72C2C1: closefrm(TABLE*, bool) (table.cc:2957)
==13153==    by 0x5E52C6: intern_close_table(TABLE*) (sql_base.cc:337)
==13153==    by 0x7D15ED: tc_release_table(TABLE*) (table_cache.cc:408)
==13153==    by 0x5E6854: close_thread_table(THD*, TABLE**) (sql_base.cc:1046)
==13153==    by 0x5E6240: close_all_tables_for_name(THD*, TABLE_SHARE*, ha_extra_function, TABLE*) (sql_base.cc:836)
==13153==    by 0x5E57E1: close_cached_tables(THD*, TABLE_LIST*, bool, unsigned long) (sql_base.cc:498)
==13153==    by 0x79C097: reload_acl_and_cache(THD*, unsigned long long, TABLE_LIST*, int*) (sql_reload.cc:300)
==13153==    by 0x650158: mysql_execute_command(THD*) (sql_parse.cc:4313)
==13153==  Block was alloc'd at
==13153==    at 0x4C2BBAF: malloc (vg_replace_malloc.c:299)
==13153==    by 0xE7B089: my_malloc (my_malloc.c:100)
==13153==    by 0xE32067: heap_open_from_share (hp_open.c:33)
==13153==    by 0xE323BF: heap_open (hp_open.c:121)
==13153==    by 0xE2C465: ha_heap::open(char const*, int, unsigned int) (ha_heap.cc:95)
==13153==    by 0x845F3D: handler::ha_open(TABLE*, char const*, int, unsigned int) (handler.cc:2525)
==13153==    by 0xE4237D: ha_partition::open(char const*, int, unsigned int) (ha_partition.cc:3492)
==13153==    by 0x845F3D: handler::ha_open(TABLE*, char const*, int, unsigned int) (handler.cc:2525)
==13153==    by 0x72BF17: open_table_from_share(THD*, TABLE_SHARE*, char const*, unsigned int, unsigned int, unsigned int, TABLE*, bool) (table.cc:2865)
==13153==    by 0x5E9449: open_table(THD*, TABLE_LIST*, st_mem_root*, Open_table_context*) (sql_base.cc:2516)
==13153==    by 0x5EBBAF: open_and_process_table(THD*, LEX*, TABLE_LIST*, unsigned int*, unsigned int, Prelocking_strategy*, bool, Open_table_context*, st_mem_root*) (sql_base.cc:4034)
==13153==    by 0x5ECC64: open_tables(THD*, TABLE_LIST**, unsigned int*, unsigned int, Prelocking_strategy*) (sql_base.cc:4568)
==13153==    by 0x64A865: lock_tables_open_and_lock_tables(THD*, TABLE_LIST*) (sql_parse.cc:2146)
==13153==    by 0x64E93E: mysql_execute_command(THD*) (sql_parse.cc:3847)
==13153==    by 0x655B91: mysql_parse(THD*, char*, unsigned int, Parser_state*) (sql_parse.cc:6583)
==13153==    by 0x6486F1: dispatch_command(enum_server_command, THD*, char*, unsigned int) (sql_parse.cc:1309)



 Comments   
Comment by Sergey Vojtovich [ 2018-10-18 ]

MySQL 5.6 and 5.7 are also affected. Fixed in MySQL 8.0 by removing partitioning.

Comment by Sergey Vojtovich [ 2018-10-18 ]

Extended test case, added two ALTER TABLE variants that cover other broken code branches:

--source include/have_partition.inc
 
CREATE TABLE t1 (i INT) ENGINE=MEMORY PARTITION BY RANGE (i) (PARTITION p0 VALUES LESS THAN (4), PARTITION pm VALUES LESS THAN MAXVALUE);
CREATE TABLE t2 (i INT) ENGINE=MEMORY;
LOCK TABLE t1 WRITE, t2 WRITE;
SELECT * FROM t1 PARTITION (p0);
FLUSH TABLES;
ALTER TABLE t1 TRUNCATE PARTITION p0;
FLUSH TABLES;
ALTER TABLE t1 EXCHANGE PARTITION p0 WITH TABLE t2;
 
# Cleanup
DROP TABLE t1;

Comment by Sergey Vojtovich [ 2018-10-18 ]

serg, please review fix for this bug.

Generated at Thu Feb 08 08:16:30 UTC 2024 using Jira 8.20.16#820016-sha1:9d11dbea5f4be3d4cc21f03a88dd11d8c8687422.