LP #1515613: Valgrind error on main.repair, main.merge, main.mysqlcheck, and main.archive

Description

**Reported in Launchpad by Laurynas Biveinis last update 03-12-2015 08:50:48

./mtr --debug-server --valgrind repair
...
main.repair [ fail ] Found warnings/errors in server log file!
Test ended at 2015-11-12 14:50:57
line
==30152== Thread 20:
==30152== Source and destination overlap in memcpy(0x14dab0c0, 0x14dab0c0, 12)
==30152== at 0x4C30573: memcpy@@GLIBC_2.14 (vg_replace_strmem.c:1018)
==30152== by 0x8E9260: open_table_from_share(THD*, TABLE_SHARE*, char const*, unsigned int, unsigned int, unsigned int, TABLE*, bool) (table.cc:2371)
==30152== by 0x9F1B3B: prepare_for_repair(THD*, TABLE_LIST*, st_ha_check_opt*) (sql_admin.cc:103)
==30152== by 0x9F298C: mysql_admin_table(THD*, TABLE_LIST*, st_ha_check_opt*, char const*, thr_lock_type, bool, bool, unsigned int, int (THD*, TABLE_LIST*, st_ha_check_opt*), int (handler::)(THD, st_ha_check_opt*), int (THD*, TABLE_LIST*)) (sql_admin.cc:451)
==30152== by 0x9F539F: Sql_cmd_repair_table::execute(THD*) (sql_admin.cc:1150)
==30152== by 0x81B174: mysql_execute_command(THD*) (sql_parse.cc:5498)
==30152== by 0x81EDBD: mysql_parse(THD*, char*, unsigned int, Parser_state*) (sql_parse.cc:6972)
==30152== by 0x810298: dispatch_command(enum_server_command, THD*, char*, unsigned int) (sql_parse.cc:1442)
==30152== by 0x80F053: do_command(THD*) (sql_parse.cc:1054)
==30152== by 0x7D20A1: do_handle_one_connection(THD*) (sql_connect.cc:1541)
==30152== by 0x7D1B39: handle_one_connection (sql_connect.cc:1444)
==30152== by 0xF2E416: pfs_spawn_thread (pfs.cc:1860)
==30152== by 0x5D376A9: start_thread (pthread_create.c:333)
==30152== by 0x68F5EEC: clone (clone.S:109)

Happens on PS 5.6 and 5.7 WIP, does not happen on either MySQL version.

Environment

None

Smart Checklist

Activity

Show:

lpjirasync January 22, 2018 at 7:47 PM

**Comment from Launchpad by: Yura Sorokin on: 23-11-2015 15:36:15

https://github.com/percona/percona-server/pull/244

lpjirasync January 22, 2018 at 7:47 PM

**Comment from Launchpad by: Yura Sorokin on: 23-11-2015 13:06:50

This is almost a false positive.

All Valgring errors come from
"restore_record(outparam, s->default_values);"
in "open_table_from_share()" in "table.cc".
This is a macro which expands to
"memcpy(outparam->record[0],outparam->s->default_values,(size_t) outparam->s->reclength)"

In all the cases ("main.repair", "main.merge", "main.mysqlcheck" and "main.archive") "source" and "dest" parameters in "memcpy" call are not just overlapping - they are identical.

Although the Standard does say that ANY overlap in memcpy() results in undefined behavior, practically "memcpy(x, x, n)" on "x86" and "x64" platforms does not change any memory (although consumes CPU cycles).
So, we are just executing unnecessary instructions.

"outparam->record[0]" and "outparam->s->default_values" can indeed be identical in the case when "records == 0"
In this case we perform
if (records == 0)
{
/* We are probably in hard repair, and the buffers should not be used */
outparam->record[0]= outparam->record[1]= share->default_values;
}

The original line
"restore_record(outparam, s->default_values);"
exists only in 5.6 and was introduces in commit c6fe9c6
https://github.com/percona/percona-server/commit/c6fe9c68d055d9c2856bcc4d20849f35f5495c88
as the fix for lp:1384568
https://bugs.launchpad.net/percona-server/+bug/1384568

Comment 17 there says
"5.1 and 5.5 are not affected. The logic behind specific SELECT is different for these versions."

The fix is straightforward
*****************************************************
if (outparam->record[0] != outparam->s->default_values)
restore_record(outparam, s->default_values);
*****************************************************

lpjirasync January 22, 2018 at 7:47 PM

**Comment from Launchpad by: Laurynas Biveinis on: 12-11-2015 13:49:35

Same top frames in the stacktrace for main.archive:

main.archive [ fail ] Found warnings/errors in server log file!
Test ended at 2015-11-12 15:48:14
line
==32464== Thread 20:
==32464== Source and destination overlap in memcpy(0xf4d7f20, 0xf4d7f20, 5)
==32464== at 0x4C30573: memcpy@@GLIBC_2.14 (vg_replace_strmem.c:1018)
==32464== by 0x8E9260: open_table_from_share(THD*, TABLE_SHARE*, char const*, unsigned int, unsigned int, unsigned int, TABLE*, bool) (table.cc:2371)
==32464== by 0x65AB15: ha_create_table_from_engine(THD*, char const*, char const*) (handler.cc:5192)
==32464== by 0x79AD0C: Open_table_context::recover_from_failed_open() (sql_base.cc:4308)
==32464== by 0x79C963: open_tables(THD*, TABLE_LIST*, unsigned int, unsigned int, Prelocking_strategy*) (sql_base.cc:5332)
==32464== by 0x79DBB9: open_normal_and_derived_tables(THD*, TABLE_LIST*, unsigned int) (sql_base.cc:6012)
==32464== by 0x7F10B1: mysql_insert(THD*, TABLE_LIST*, List<Item>&, List<List<Item> >&, List<Item>&, List<Item>&, enum_duplicates, bool) (sql_insert.cc:750)
==32464== by 0x816458: mysql_execute_command(THD*) (sql_parse.cc:3904)
==32464== by 0x81EDBD: mysql_parse(THD*, char*, unsigned int, Parser_state*) (sql_parse.cc:6972)
==32464== by 0x810298: dispatch_command(enum_server_command, THD*, char*, unsigned int) (sql_parse.cc:1442)
==32464== by 0x80F053: do_command(THD*) (sql_parse.cc:1054)
==32464== by 0x7D20A1: do_handle_one_connection(THD*) (sql_connect.cc:1541)
==32464== by 0x7D1B39: handle_one_connection (sql_connect.cc:1444)
==32464== by 0xF2E416: pfs_spawn_thread (pfs.cc:1860)
==32464== by 0x5D376A9: start_thread (pthread_create.c:333)
==32464== by 0x68F5EEC: clone (clone.S:109)
==32464== Source and destination overlap in memcpy(0xf5e8970, 0xf5e8970, 5)
==32464== at 0x4C30573: memcpy@@GLIBC_2.14 (vg_replace_strmem.c:1018)
==32464== by 0x8E9260: open_table_from_share(THD*, TABLE_SHARE*, char const*, unsigned int, unsigned int, unsigned int, TABLE*, bool) (table.cc:2371)
==32464== by 0x65AB15: ha_create_table_from_engine(THD*, char const*, char const*) (handler.cc:5192)
==32464== by 0x888CBE: mysql_rm_table_no_locks(THD*, TABLE_LIST*, bool, bool, bool, bool) (sql_table.cc:2504)
==32464== by 0x8882DA: mysql_rm_table(THD*, TABLE_LIST*, char, char) (sql_table.cc:2223)
==32464== by 0x816F16: mysql_execute_command(THD*) (sql_parse.cc:4104)
==32464== by 0x81EDBD: mysql_parse(THD*, char*, unsigned int, Parser_state*) (sql_parse.cc:6972)
==32464== by 0x810298: dispatch_command(enum_server_command, THD*, char*, unsigned int) (sql_parse.cc:1442)
==32464== by 0x80F053: do_command(THD*) (sql_parse.cc:1054)
==32464== by 0x7D20A1: do_handle_one_connection(THD*) (sql_connect.cc:1541)
==32464== by 0x7D1B39: handle_one_connection (sql_connect.cc:1444)
==32464== by 0xF2E416: pfs_spawn_thread (pfs.cc:1860)
==32464== by 0x5D376A9: start_thread (pthread_create.c:333)
==32464== by 0x68F5EEC: clone (clone.S:109)

lpjirasync January 22, 2018 at 7:47 PM

**Comment from Launchpad by: Laurynas Biveinis on: 12-11-2015 12:58:56

Same stacktrace on main.mysqlcheck:

main.mysqlcheck [ fail ] Found warnings/errors in server log file!
Test ended at 2015-11-12 14:58:26
line
==30570== Thread 21:
==30570== Source and destination overlap in memcpy(0x158703e0, 0x158703e0, 5)
==30570== at 0x4C30573: memcpy@@GLIBC_2.14 (vg_replace_strmem.c:1018)
==30570== by 0x8E9260: open_table_from_share(THD*, TABLE_SHARE*, char const*, unsigned int, unsigned int, unsigned int, TABLE*, bool) (table.cc:2371)
==30570== by 0x9F1B3B: prepare_for_repair(THD*, TABLE_LIST*, st_ha_check_opt*) (sql_admin.cc:103)
==30570== by 0x9F298C: mysql_admin_table(THD*, TABLE_LIST*, st_ha_check_opt*, char const*, thr_lock_type, bool, bool, unsigned int, int (THD*, TABLE_LIST*, st_ha_check_opt*), int (handler::)(THD, st_ha_check_opt*), int (THD*, TABLE_LIST*)) (sql_admin.cc:451)
==30570== by 0x9F539F: Sql_cmd_repair_table::execute(THD*) (sql_admin.cc:1150)
==30570== by 0x81B174: mysql_execute_command(THD*) (sql_parse.cc:5498)
==30570== by 0x81EDBD: mysql_parse(THD*, char*, unsigned int, Parser_state*) (sql_parse.cc:6972)
==30570== by 0x810298: dispatch_command(enum_server_command, THD*, char*, unsigned int) (sql_parse.cc:1442)
==30570== by 0x80F053: do_command(THD*) (sql_parse.cc:1054)
==30570== by 0x7D20A1: do_handle_one_connection(THD*) (sql_connect.cc:1541)
==30570== by 0x7D1B39: handle_one_connection (sql_connect.cc:1444)
==30570== by 0xF2E416: pfs_spawn_thread (pfs.cc:1860)
==30570== by 0x5D376A9: start_thread (pthread_create.c:333)
==30570== by 0x68F5EEC: clone (clone.S:109)
^ Found warnings in /home/laurynas/obj-percona-5.6-valgrind/mysql-test/var/log/mysqld.1.err

lpjirasync January 22, 2018 at 7:47 PM

**Comment from Launchpad by: Laurynas Biveinis on: 12-11-2015 12:57:06

Same stacktrace on main.merge:

main.merge [ fail ] Found warnings/errors in server log file!
Test ended at 2015-11-12 14:56:08
line
==30397== Thread 20:
==30397== Source and destination overlap in memcpy(0x14f59a80, 0x14f59a80, 9)
==30397== at 0x4C30573: memcpy@@GLIBC_2.14 (vg_replace_strmem.c:1018)
==30397== by 0x8E9260: open_table_from_share(THD*, TABLE_SHARE*, char const*, unsigned int, unsigned int, unsigned int, TABLE*, bool) (table.cc:2371)
==30397== by 0x9F1B3B: prepare_for_repair(THD*, TABLE_LIST*, st_ha_check_opt*) (sql_admin.cc:103)
==30397== by 0x9F298C: mysql_admin_table(THD*, TABLE_LIST*, st_ha_check_opt*, char const*, thr_lock_type, bool, bool, unsigned int, int (THD*, TABLE_LIST*, st_ha_check_opt*), int (handler::)(THD, st_ha_check_opt*), int (THD*, TABLE_LIST*)) (sql_admin.cc:451)
==30397== by 0x9F539F: Sql_cmd_repair_table::execute(THD*) (sql_admin.cc:1150)
==30397== by 0x81B174: mysql_execute_command(THD*) (sql_parse.cc:5498)
==30397== by 0x81EDBD: mysql_parse(THD*, char*, unsigned int, Parser_state*) (sql_parse.cc:6972)
==30397== by 0x810298: dispatch_command(enum_server_command, THD*, char*, unsigned int) (sql_parse.cc:1442)
==30397== by 0x80F053: do_command(THD*) (sql_parse.cc:1054)
==30397== by 0x7D20A1: do_handle_one_connection(THD*) (sql_connect.cc:1541)
==30397== by 0x7D1B39: handle_one_connection (sql_connect.cc:1444)
==30397== by 0xF2E416: pfs_spawn_thread (pfs.cc:1860)
==30397== by 0x5D376A9: start_thread (pthread_create.c:333)
==30397== by 0x68F5EEC: clone (clone.S:109)

Done

Details

Assignee

Reporter

Priority

Smart Checklist

Created January 22, 2018 at 7:46 PM
Updated January 22, 2018 at 7:47 PM
Resolved January 22, 2018 at 7:46 PM