From 33878ac87a319a06c797c66e58ef3f04d7ce09f6 Mon Sep 17 00:00:00 2001 From: "monty@mysql.com" <> Date: Wed, 26 Jan 2005 12:55:35 +0200 Subject: [PATCH 1/3] Added -DDBUG_ON to CXXFLAGS when compiling with debugging This fixes a memory allocation bug in Innobase as structs was defined differently in .c and .cc files --- configure.in | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/configure.in b/configure.in index cc845a7bb8d..3e9ea6eebe7 100644 --- a/configure.in +++ b/configure.in @@ -1681,12 +1681,12 @@ if test "$with_debug" = "yes" then # Medium debug. CFLAGS="$DEBUG_CFLAGS $DEBUG_OPTIMIZE_CC -DDBUG_ON -DSAFE_MUTEX $CFLAGS" - CXXFLAGS="$DEBUG_CXXFLAGS $DEBUG_OPTIMIZE_CXX -DSAFE_MUTEX $CXXFLAGS" + CXXFLAGS="$DEBUG_CXXFLAGS $DEBUG_OPTIMIZE_CXX -DDBUG_ON -DSAFE_MUTEX $CXXFLAGS" elif test "$with_debug" = "full" then # Full debug. Very slow in some cases CFLAGS="$DEBUG_CFLAGS -DDBUG_ON -DSAFE_MUTEX -DSAFEMALLOC $CFLAGS" - CXXFLAGS="$DEBUG_CXXFLAGS -DSAFE_MUTEX -DSAFEMALLOC $CXXFLAGS" + CXXFLAGS="$DEBUG_CXXFLAGS -DDBUG_ON -DSAFE_MUTEX -DSAFEMALLOC $CXXFLAGS" else # Optimized version. No debug CFLAGS="$OPTIMIZE_CFLAGS -DDBUG_OFF $CFLAGS" From f16b456ddc79c48af9070c79cb1593c0e1f6d989 Mon Sep 17 00:00:00 2001 From: "monty@mysql.com" <> Date: Wed, 26 Jan 2005 16:07:53 +0200 Subject: [PATCH 2/3] Only enable Innodb extra debugging when using the --debug=full configure option --- BUILD/SETUP.sh | 8 ++++++-- BUILD/compile-pentium64-debug | 2 +- configure.in | 4 ++-- innobase/fil/fil0fil.c | 6 +++--- innobase/include/univ.i | 4 ++++ 5 files changed, 16 insertions(+), 8 deletions(-) mode change 100644 => 100755 BUILD/SETUP.sh diff --git a/BUILD/SETUP.sh b/BUILD/SETUP.sh old mode 100644 new mode 100755 index 5fe898878b9..77fab948121 --- a/BUILD/SETUP.sh +++ b/BUILD/SETUP.sh @@ -25,7 +25,10 @@ Any other options will be passed directly to configure. Note: this script is intended for internal use by MySQL developers. EOF --with-debug=full ) full_debug="=full"; shift ;; - * ) break ;; + * ) + echo "Unknown option '$1'" + exit 1 + break ;; esac done @@ -62,6 +65,7 @@ fast_cflags="-O3 -fno-omit-frame-pointer" reckless_cflags="-O3 -fomit-frame-pointer " debug_cflags="-DUNIV_MUST_NOT_INLINE -DEXTRA_DEBUG -DFORCE_INIT_OF_VARS -DSAFEMALLOC -DPEDANTIC_SAFEMALLOC -DSAFE_MUTEX" +debug_extra_cflags="-O1 -Wuninitialized" base_cxxflags="-felide-constructors -fno-exceptions -fno-rtti" amd64_cxxflags="-DBIG_TABLES" @@ -80,7 +84,7 @@ local_infile_configs="--enable-local-infile" debug_configs="--with-debug$full_debug" if [ -z "$full_debug" ] then - debug_cflags="$debug_cflags -O1 -Wuninitialized" + debug_cflags="$debug_cflags $debug_extra_cflags" fi if gmake --version > /dev/null 2>&1 diff --git a/BUILD/compile-pentium64-debug b/BUILD/compile-pentium64-debug index 1bbca36d851..0299669f79a 100755 --- a/BUILD/compile-pentium64-debug +++ b/BUILD/compile-pentium64-debug @@ -1,7 +1,7 @@ #! /bin/sh path=`dirname $0` -. "$path/SETUP.sh" +. "$path/SETUP.sh" $@ --with-debug=full extra_flags="$pentium64_cflags $debug_cflags" c_warnings="$c_warnings $debug_extra_warnings" diff --git a/configure.in b/configure.in index 3e9ea6eebe7..985b5923c5c 100644 --- a/configure.in +++ b/configure.in @@ -1685,8 +1685,8 @@ then elif test "$with_debug" = "full" then # Full debug. Very slow in some cases - CFLAGS="$DEBUG_CFLAGS -DDBUG_ON -DSAFE_MUTEX -DSAFEMALLOC $CFLAGS" - CXXFLAGS="$DEBUG_CXXFLAGS -DDBUG_ON -DSAFE_MUTEX -DSAFEMALLOC $CXXFLAGS" + CFLAGS="$DEBUG_CFLAGS -DDBUG_ON -DSAFE_MUTEX -DSAFEMALLOC -DUNIV_DEBUG $CFLAGS" + CXXFLAGS="$DEBUG_CXXFLAGS -DDBUG_ON -DSAFE_MUTEX -DSAFEMALLOC -DUNIV_DEBUG $CXXFLAGS" else # Optimized version. No debug CFLAGS="$OPTIMIZE_CFLAGS -DDBUG_OFF $CFLAGS" diff --git a/innobase/fil/fil0fil.c b/innobase/fil/fil0fil.c index 5f71c00aea6..cc1c4a22983 100644 --- a/innobase/fil/fil0fil.c +++ b/innobase/fil/fil0fil.c @@ -685,9 +685,9 @@ fil_try_to_close_file_in_LRU( fputs("InnoDB: cannot close file ", stderr); ut_print_filename(stderr, node->name); fprintf(stderr, - ", because mod_count %lld != fl_count %lld\n", - node->modification_counter, - node->flush_counter); + ", because mod_count %ld != fl_count %ld\n", + (ulong) node->modification_counter, + (ulong) node->flush_counter); } node = UT_LIST_GET_PREV(LRU, node); diff --git a/innobase/include/univ.i b/innobase/include/univ.i index 625978ffc38..6ae4fe1c2ce 100644 --- a/innobase/include/univ.i +++ b/innobase/include/univ.i @@ -80,6 +80,10 @@ memory is read outside the allocated blocks. */ /* Make a non-inline debug version */ +#ifdef DBUG_ON +#define UNIV_DEBUG +#endif /* DBUG_ON */ + /* #define UNIV_DEBUG #define UNIV_MEM_DEBUG From 5ad151aa213631cf819d3f650d6c8cb37a7a76a7 Mon Sep 17 00:00:00 2001 From: "ingo@mysql.com" <> Date: Wed, 26 Jan 2005 15:27:31 +0100 Subject: [PATCH 3/3] Test Bug: Memory leaks in the archive handler. Moved initialization code into a new init function. Added a new cleanup function. Added a call to close the meta file. --- mysql-test/t/archive.test | 2 +- sql/examples/ha_archive.cc | 59 ++++++++++++++++++++++++++------------ sql/examples/ha_archive.h | 4 +++ sql/handler.cc | 14 +++++++++ 4 files changed, 60 insertions(+), 19 deletions(-) diff --git a/mysql-test/t/archive.test b/mysql-test/t/archive.test index f55aea6e104..ee78b53f9c8 100644 --- a/mysql-test/t/archive.test +++ b/mysql-test/t/archive.test @@ -1,6 +1,6 @@ # # Simple test for archive example -# Taken fromm the select test +# Taken from the select test # -- source include/have_archive.inc diff --git a/sql/examples/ha_archive.cc b/sql/examples/ha_archive.cc index ef609513489..e8d07a99048 100644 --- a/sql/examples/ha_archive.cc +++ b/sql/examples/ha_archive.cc @@ -116,7 +116,6 @@ /* Variables for archive share methods */ pthread_mutex_t archive_mutex; static HASH archive_open_tables; -static int archive_init= 0; /* The file extension */ #define ARZ ".ARZ" // The data file @@ -142,6 +141,46 @@ static byte* archive_get_key(ARCHIVE_SHARE *share,uint *length, return (byte*) share->table_name; } + +/* + Initialize the archive handler. + + SYNOPSIS + archive_db_init() + void + + RETURN + FALSE OK + TRUE Error +*/ + +bool archive_db_init() +{ + VOID(pthread_mutex_init(&archive_mutex, MY_MUTEX_INIT_FAST)); + return (hash_init(&archive_open_tables, system_charset_info, 32, 0, 0, + (hash_get_key) archive_get_key, 0, 0)); +} + + +/* + Release the archive handler. + + SYNOPSIS + archive_db_end() + void + + RETURN + FALSE OK +*/ + +bool archive_db_end() +{ + hash_free(&archive_open_tables); + VOID(pthread_mutex_destroy(&archive_mutex)); + return FALSE; +} + + /* This method reads the header of a datafile and returns whether or not it was successful. */ @@ -269,23 +308,6 @@ ARCHIVE_SHARE *ha_archive::get_share(const char *table_name, TABLE *table) uint length; char *tmp_name; - if (!archive_init) - { - /* Hijack a mutex for init'ing the storage engine */ - pthread_mutex_lock(&LOCK_mysql_create_db); - if (!archive_init) - { - VOID(pthread_mutex_init(&archive_mutex,MY_MUTEX_INIT_FAST)); - if (hash_init(&archive_open_tables,system_charset_info,32,0,0, - (hash_get_key) archive_get_key,0,0)) - { - pthread_mutex_unlock(&LOCK_mysql_create_db); - return NULL; - } - archive_init++; - } - pthread_mutex_unlock(&LOCK_mysql_create_db); - } pthread_mutex_lock(&archive_mutex); length=(uint) strlen(table_name); @@ -379,6 +401,7 @@ int ha_archive::free_share(ARCHIVE_SHARE *share) (void)write_meta_file(share->meta_file, share->rows_recorded, FALSE); if (gzclose(share->archive_write) == Z_ERRNO) rc= 1; + my_close(share->meta_file,MYF(0)); my_free((gptr) share, MYF(0)); } pthread_mutex_unlock(&archive_mutex); diff --git a/sql/examples/ha_archive.h b/sql/examples/ha_archive.h index b619de5f6c1..855d756368d 100644 --- a/sql/examples/ha_archive.h +++ b/sql/examples/ha_archive.h @@ -125,3 +125,7 @@ public: THR_LOCK_DATA **store_lock(THD *thd, THR_LOCK_DATA **to, enum thr_lock_type lock_type); }; + +bool archive_db_init(void); +bool archive_db_end(void); + diff --git a/sql/handler.cc b/sql/handler.cc index 3200c6932e9..70ba236a5d5 100644 --- a/sql/handler.cc +++ b/sql/handler.cc @@ -277,6 +277,16 @@ int ha_init() else opt_using_transactions=1; } +#endif +#ifdef HAVE_ARCHIVE_DB + if (have_archive_db == SHOW_OPTION_YES) + { + if (archive_db_init()) + { + have_archive_db= SHOW_OPTION_DISABLED; + error= 1; + } + } #endif return error; } @@ -308,6 +318,10 @@ int ha_panic(enum ha_panic_function flag) #ifdef HAVE_NDBCLUSTER_DB if (have_ndbcluster == SHOW_OPTION_YES) error|=ndbcluster_end(); +#endif +#ifdef HAVE_ARCHIVE_DB + if (have_archive_db == SHOW_OPTION_YES) + error|= archive_db_end(); #endif return error; } /* ha_panic */