Bug #27143 InnoDB crashes under Windows when testing in Debug mode
Submitted: 14 Mar 2007 17:30 Modified: 25 Jul 2007 2:15
Reporter: Paul McCullagh (Basic Quality Contributor) (OCA) Email Updates:
Status: Closed Impact on me:
None 
Category:MySQL Server: InnoDB storage engine Severity:S6 (Debug Builds)
Version:5.1.16 OS:Windows (Windows NT/XP)
Assigned to: Sunny Bains CPU Architecture:Any
Tags: debug, innodb, myfree, qc, upd_buff, windows

[14 Mar 2007 17:30] Paul McCullagh
Description:
When testing using mysql-test-run under Windows with a debug build of MySQL, InnoDB crashes in ha_innobase::close() on the following line:

	my_free((gptr) upd_buff, MYF(0));

This occurs because InnoDB is not compiled with the flags SAFEMALLOC.

Both SAFEMALLOC and  SAFE_MUTEX are defined in the debug version of the mysqld project.

How to repeat:
Confirm the following:

upd_buff is allocated in ha_innobase::open() on the following line:

	if (!(mysql_byte*) my_multi_malloc(MYF(MY_WME),
			&upd_buff, upd_and_key_val_buff_len,
			&key_val_buff, upd_and_key_val_buff_len,
			NullS)) {

my_multi_malloc() is a function defined in mulalloc.c, part of the mysqld code which is compiled with SAFEMALLOC. As a result, this code returns a "debug" pointer.

my_free() on the other hand, is a macro. Since SAFEMALLOC is not defined where it is called, it is defined as the system function free().

free() crashes when tryng to free the debug pointer, which is not a valid for free().

Suggested fix:
Just like the mysqld project, the innodb debug project must include the definition of SAFEMALLOC and SAFE_MUTEX.
[15 Mar 2007 2:17] MySQL Verification Team
Thank you for the bug report.

miguel@skybr /cygdrive/c/build/mysql-5.1/mysql-test
$ ./mysql-test-run.pl
Logging: ./mysql-test-run.pl
MySQL Version 5.1.17
Using binlog format 'mixed'
Disable Instance manager - not supported on Windows
Skipping ndbcluster, mysqld not compiled with ndbcluster
Setting mysqld to support SSL connections
Binaries are debug compiled
Using MTR_BUILD_THREAD      = 0
Using MASTER_MYPORT         = 9306
Using MASTER_MYPORT1        = 9307
Using SLAVE_MYPORT          = 9308
Using SLAVE_MYPORT1         = 9309
Using SLAVE_MYPORT2         = 9310
Killing Possible Leftover Processes
kill: couldn't open pid 1128
Removing Stale Files
Creating Directories
Installing Master Database
Installing Master Database
Installing Slave1 Database
=======================================================
Starting Tests in the 'main' suite

TEST                           RESULT         TIME (ms)
-------------------------------------------------------

1st                            [ pass ]            392
alias                          [ fail ]

Errors are (from c:/build/mysql-5.1/mysql-test/var/log/mysqltest-time) :
mysqltest: At line 2: query 'DROP TABLE IF EXISTS t1' failed: 2013: Lost connection to MySQL server durin
g query
(the last lines may be the most important ones)
Result from queries before failure can be found in c:/build/mysql-5.1/mysql-test/var/log/alias.log

>	mysqld.exe!_lseeki64(int fh=-1, __int64 pos=0, int mthd=1)  Line 78 + 0x4a bytes	C
 	mysqld.exe!_telli64(int filedes=-1)  Line 37 + 0xf bytes	C
 	mysqld.exe!my_tell(int fd=-1, int MyFlags=0)  Line 83 + 0x9 bytes	C
 	mysqld.exe!init_io_cache(st_io_cache * info=0x02737d28, int file=-1, unsigned int cachesize=32768, cache_type type=WRITE_CACHE, unsigned __int64 seek_offset=0, int use_async_io=0, int cache_myflags=20)  Line 174 + 0xb bytes	C
 	mysqld.exe!open_cached_file(st_io_cache * cache=0x02737d28, const char * dir=0x001626b0, const char * prefix=0x00ae9eb0, unsigned int cache_size=32768, int cache_myflags=16)  Line 70 + 0x1e bytes	C
 	mysqld.exe!THD::binlog_setup_trx_data()  Line 3395 + 0x2b bytes	C++
 	mysqld.exe!MYSQL_BIN_LOG::write(Log_event * event_info=0x0a08e680)  Line 3725 + 0x8 bytes	C++
 	mysqld.exe!THD::binlog_query(THD::enum_binlog_query_type qtype=STMT_QUERY_TYPE, const char * query=0x028a4a60, unsigned long query_len=23, int is_trans=0, int suppress_use=0)  Line 2865 + 0x11 bytes	C++
 	mysqld.exe!write_bin_log(THD * thd=0x0286d940, int clear_error=1, const char * query=0x028a4a60, unsigned long query_length=23)  Line 1456	C++
 	mysqld.exe!mysql_rm_table_part2(THD * thd=0x0286d940, st_table_list * tables=0x028a4ad8, int if_exists=1, int drop_temporary=0, int drop_view=0, int dont_log_query=0)  Line 1802 + 0x2a bytes	C++
 	mysqld.exe!mysql_rm_table(THD * thd=0x0286d940, st_table_list * tables=0x028a4ad8, char if_exists='', char drop_temporary=0)  Line 1510 + 0x1b bytes	C++
 	mysqld.exe!mysql_execute_command(THD * thd=0x0286d940)  Line 2695 + 0x21 bytes	C++
 	mysqld.exe!mysql_parse(THD * thd=0x0286d940, char * inBuf=0x028a4a60, unsigned int length=23)  Line 5186 + 0x9 bytes	C++
 	mysqld.exe!dispatch_command(enum_server_command command=COM_QUERY, THD * thd=0x0286d940, char * packet=0x0289c9b1, unsigned int packet_length=24)  Line 880 + 0x1d bytes	C++
 	mysqld.exe!do_command(THD * thd=0x0286d940)  Line 649 + 0x31 bytes	C++
 	mysqld.exe!handle_one_connection(void * arg=0x0286d940)  Line 1089 + 0x9 bytes	C++
 	mysqld.exe!pthread_start(void * param=0x01b1fb98)  Line 62 + 0x9 bytes	C
 	mysqld.exe!_callthreadstart()  Line 293 + 0xf bytes	C
 	mysqld.exe!_threadstart(void * ptd=0x02737ad0)  Line 277	C
 	kernel32.dll!776a3833() 	
 	[Frames below may be incorrect and/or missing, no symbols loaded for kernel32.dll]	
 	ntdll.dll!7753a9bd()
[15 Mar 2007 7:32] Paul McCullagh
This crash demonstrates bug #27141 (http://bugs.mysql.com/bug.php?id=27141).

To repeat this bug with mysql-test-run under windows, execute the following:

perl mysql-test-run.pl --do-test=binlog_stm_innodb_stat.test
[15 Mar 2007 13:10] Heikki Tuuri
Paul,

thank you for spotting this!

I guess removing the comment marks '#' below will fix this in the Windows build.

# Copyright (C) 2006 MySQL AB
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; version 2 of the License.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA

#SET(CMAKE_CXX_FLAGS_DEBUG "-DSAFEMALLOC -DSAFE_MUTEX")
#SET(CMAKE_C_FLAGS_DEBUG "-DSAFEMALLOC -DSAFE_MUTEX")
ADD_DEFINITIONS(-DMYSQL_SERVER -D_WIN32 -DWIN32 -D_LIB)

Assigning this to Sunny.

Regards,

Heikki
[15 Mar 2007 13:15] Heikki Tuuri
Or maybe we should copy the definitions from CMakeLists.txt of MyISAM:

SET(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -DSAFEMALLOC -DSAFE_MUTEX")
SET(CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS_DEBUG} -DSAFEMALLOC -DSAFE_MUTEX")

?
[15 Mar 2007 13:24] Paul McCullagh
Hi Heikki,

Apparently, the following (for example) works:

SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DMYSQL_SERVER")
SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -DMYSQL_SERVER")

SET(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -DMYSQL_SERVER -DSAFEMALLOC -DSAFE_MUTEX -DDEBUG")
SET(CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS_DEBUG} -DMYSQL_SERVER -DSAFEMALLOC -DSAFE_MUTEX -DDEBUG")

Best regards,

Paul
[15 Mar 2007 14:17] Heikki Tuuri
Paul,

thank you!

Sunny, please put the patch proposed by Paul to InnoDB-5.1.

Heikki