From f56dd32bf7c5b8a8cf35984f39f1a253b75945ff Mon Sep 17 00:00:00 2001 From: Davi Arnaut Date: Thu, 8 Jul 2010 18:20:08 -0300 Subject: Bug#34043: Server loops excessively in _checkchunk() when safemalloc is enabled Essentially, the problem is that safemalloc is excruciatingly slow as it checks all allocated blocks for overrun at each memory management primitive, yielding a almost exponential slowdown for the memory management functions (malloc, realloc, free). The overrun check basically consists of verifying some bytes of a block for certain magic keys, which catches some simple forms of overrun. Another minor problem is violation of aliasing rules and that its own internal list of blocks is prone to corruption. Another issue with safemalloc is rather the maintenance cost as the tool has a significant impact on the server code. Given the magnitude of memory debuggers available nowadays, especially those that are provided with the platform malloc implementation, maintenance of a in-house and largely obsolete memory debugger becomes a burden that is not worth the effort due to its slowness and lack of support for detecting more common forms of heap corruption. Since there are third-party tools that can provide the same functionality at a lower or comparable performance cost, the solution is to simply remove safemalloc. Third-party tools can provide the same functionality at a lower or comparable performance cost. The removal of safemalloc also allows a simplification of the malloc wrappers, removing quite a bit of kludge: redefinition of my_malloc, my_free and the removal of the unused second argument of my_free. Since free() always check whether the supplied pointer is null, redudant checks are also removed. Also, this patch adds unit testing for my_malloc and moves my_realloc implementation into the same file as the other memory allocation primitives. client/mysqldump.c: Pass my_free directly as its signature is compatible with the callback type -- which wasn't the case for free_table_ent. --- libmysql/Makefile.am | 2 +- libmysql/Makefile.shared | 4 ++-- libmysql/libmysql.c | 16 ++++++++-------- 3 files changed, 11 insertions(+), 11 deletions(-) (limited to 'libmysql') diff --git a/libmysql/Makefile.am b/libmysql/Makefile.am index b1d23a175d4..8aa1648c834 100644 --- a/libmysql/Makefile.am +++ b/libmysql/Makefile.am @@ -79,7 +79,7 @@ link_sources: # a minimal MySQL client library # # For a really minimal distribution (without debugging code) we could -# keep only the stubs for safemalloc.c and debug.c +# keep only the stubs for debug.c # # A list of needed headers collected from the deps information 000213 nh = my_global.h config-win32.h dbug.h errmsg.h \ diff --git a/libmysql/Makefile.shared b/libmysql/Makefile.shared index 71a4fd867bd..2b413831076 100644 --- a/libmysql/Makefile.shared +++ b/libmysql/Makefile.shared @@ -49,7 +49,7 @@ mystringsobjects = strmov.lo strxmov.lo strxnmov.lo strnmov.lo \ ctype-uca.lo xml.lo my_strtoll10.lo str_alloc.lo dtoa.lo mystringsextra= strto.c -dbugobjects = dbug.lo # IT IS IN SAFEMALLOC.C sanity.lo +dbugobjects = dbug.lo mysysheaders = mysys_priv.h my_static.h vioheaders = vio_priv.h mysysobjects1 = my_init.lo my_static.lo my_malloc.lo my_realloc.lo \ @@ -57,7 +57,7 @@ mysysobjects1 = my_init.lo my_static.lo my_malloc.lo my_realloc.lo \ my_file.lo my_read.lo my_write.lo errors.lo \ my_error.lo my_getwd.lo my_div.lo \ mf_pack.lo my_mess.lo mf_dirname.lo mf_fn_ext.lo\ - mf_wcomp.lo typelib.lo safemalloc.lo my_alloc.lo \ + mf_wcomp.lo typelib.lo my_alloc.lo \ mf_format.lo mf_path.lo mf_unixpath.lo my_fopen.lo \ my_symlink.lo my_fstream.lo mf_arr_appstr.lo \ mf_loadpath.lo my_pthread.lo my_thr_init.lo \ diff --git a/libmysql/libmysql.c b/libmysql/libmysql.c index 901fa1f0c4c..b69c27731dd 100644 --- a/libmysql/libmysql.c +++ b/libmysql/libmysql.c @@ -341,7 +341,7 @@ mysql_connect(MYSQL *mysql,const char *host, if (!(res=mysql_real_connect(mysql,host,user,passwd,NullS,0,NullS,0))) { if (mysql->free_me) - my_free((uchar*) mysql,MYF(0)); + my_free(mysql); } mysql->reconnect= 1; DBUG_RETURN(res); @@ -457,9 +457,9 @@ my_bool STDCALL mysql_change_user(MYSQL *mysql, const char *user, if (rc == 0) { /* Free old connect information */ - my_free(mysql->user,MYF(MY_ALLOW_ZERO_PTR)); - my_free(mysql->passwd,MYF(MY_ALLOW_ZERO_PTR)); - my_free(mysql->db,MYF(MY_ALLOW_ZERO_PTR)); + my_free(mysql->user); + my_free(mysql->passwd); + my_free(mysql->db); /* alloc new connect information */ mysql->user= my_strdup(user,MYF(MY_WME)); @@ -604,7 +604,7 @@ my_bool handle_local_infile(MYSQL *mysql, const char *net_filename) err: /* free up memory allocated with _init, usually */ (*options->local_infile_end)(li_ptr); - my_free(buf, MYF(0)); + my_free(buf); DBUG_RETURN(result); } @@ -715,7 +715,7 @@ static void default_local_infile_end(void *ptr) { if (data->fd >= 0) my_close(data->fd, MYF(MY_WME)); - my_free(ptr, MYF(MY_WME)); + my_free(ptr); } } @@ -2206,7 +2206,7 @@ int cli_stmt_execute(MYSQL_STMT *stmt) } result= execute(stmt, param_data, length); stmt->send_types_to_server=0; - my_free(param_data, MYF(MY_WME)); + my_free(param_data); DBUG_RETURN(result); } DBUG_RETURN((int) execute(stmt,0,0)); @@ -4707,7 +4707,7 @@ my_bool STDCALL mysql_stmt_close(MYSQL_STMT *stmt) } } - my_free((uchar*) stmt, MYF(MY_WME)); + my_free(stmt); DBUG_RETURN(test(rc)); } -- cgit v1.2.1 From 2ccaf604e2aa7ee60a25933671855c8035e6d47c Mon Sep 17 00:00:00 2001 From: Davi Arnaut Date: Fri, 9 Jul 2010 08:18:36 -0300 Subject: Bug#34043: Server loops excessively in _checkchunk() when safemalloc is enabled Post-merge fix: remove reference to file that is now gone. --- libmysql/Makefile.shared | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'libmysql') diff --git a/libmysql/Makefile.shared b/libmysql/Makefile.shared index 2b413831076..e972a6bdec8 100644 --- a/libmysql/Makefile.shared +++ b/libmysql/Makefile.shared @@ -52,7 +52,7 @@ mystringsextra= strto.c dbugobjects = dbug.lo mysysheaders = mysys_priv.h my_static.h vioheaders = vio_priv.h -mysysobjects1 = my_init.lo my_static.lo my_malloc.lo my_realloc.lo \ +mysysobjects1 = my_init.lo my_static.lo my_malloc.lo \ my_create.lo my_delete.lo mf_tempfile.lo my_open.lo \ my_file.lo my_read.lo my_write.lo errors.lo \ my_error.lo my_getwd.lo my_div.lo \ -- cgit v1.2.1 From 07e7b4d6fe590cb49a5009842d3153520f2e1a36 Mon Sep 17 00:00:00 2001 From: Davi Arnaut Date: Thu, 15 Jul 2010 08:13:30 -0300 Subject: WL#5486: Remove code for unsupported platforms Remove Netware specific code. --- libmysql/get_password.c | 14 ++------------ libmysql/libmysql.c | 12 ++---------- 2 files changed, 4 insertions(+), 22 deletions(-) (limited to 'libmysql') diff --git a/libmysql/get_password.c b/libmysql/get_password.c index cbe5fce6949..56514a8d864 100644 --- a/libmysql/get_password.c +++ b/libmysql/get_password.c @@ -36,7 +36,7 @@ #include #endif /* HAVE_PWD_H */ #else /* ! HAVE_GETPASS */ -#if !defined(__WIN__) && !defined(__NETWARE__) +#if !defined(__WIN__) #include #ifdef HAVE_TERMIOS_H /* For tty-password */ #include @@ -55,9 +55,7 @@ #include #endif #else -#ifndef __NETWARE__ #include -#endif /* __NETWARE__ */ #endif /* __WIN__ */ #endif /* HAVE_GETPASS */ @@ -65,16 +63,8 @@ #define getpass(A) getpassphrase(A) #endif -#if defined( __WIN__) || defined(__NETWARE__) +#if defined(__WIN__) /* were just going to fake it here and get input from the keyboard */ - -#ifdef __NETWARE__ -#undef _getch -#undef _cputs -#define _getch getcharacter -#define _cputs(A) putstring(A) -#endif - char *get_tty_password(const char *opt_message) { char to[80]; diff --git a/libmysql/libmysql.c b/libmysql/libmysql.c index b69c27731dd..68813937fb6 100644 --- a/libmysql/libmysql.c +++ b/libmysql/libmysql.c @@ -165,7 +165,7 @@ int STDCALL mysql_server_init(int argc __attribute__((unused)), mysql_unix_port = env; } mysql_debug(NullS); -#if defined(SIGPIPE) && !defined(__WIN__) && !defined(__NETWARE__) +#if defined(SIGPIPE) && !defined(__WIN__) (void) signal(SIGPIPE, SIG_IGN); #endif #ifdef EMBEDDED_LIBRARY @@ -479,15 +479,7 @@ struct passwd *getpwuid(uid_t); char* getlogin(void); #endif -#if defined(__NETWARE__) -/* Default to value of USER on NetWare, if unset use "UNKNOWN_USER" */ -void read_user_name(char *name) -{ - char *str=getenv("USER"); - strmake(name, str ? str : "UNKNOWN_USER", USERNAME_LENGTH); -} - -#elif !defined(MSDOS) && ! defined(VMS) && !defined(__WIN__) +#if !defined(MSDOS) && ! defined(VMS) && !defined(__WIN__) void read_user_name(char *name) { -- cgit v1.2.1 From 13f7a1d2447c002adc36dd1bd51305edbc8e8636 Mon Sep 17 00:00:00 2001 From: Davi Arnaut Date: Thu, 15 Jul 2010 08:16:06 -0300 Subject: WL#5486: Remove code for unsupported platforms Remove MS-DOS specific code. --- libmysql/dll.c | 20 +------------------- libmysql/libmysql.c | 46 ++++++++++++++++++++++------------------------ 2 files changed, 23 insertions(+), 43 deletions(-) (limited to 'libmysql') diff --git a/libmysql/dll.c b/libmysql/dll.c index 8fcf41c792c..b5fcba13f91 100644 --- a/libmysql/dll.c +++ b/libmysql/dll.c @@ -48,7 +48,7 @@ void libmysql_init(void) #ifdef __WIN__ static int inited=0,threads=0; -HINSTANCE NEAR s_hModule; /* Saved module handle */ +HINSTANCE s_hModule; /* Saved module handle */ DWORD main_thread; BOOL APIENTRY LibMain(HANDLE hInst,DWORD ul_reason_being_called, @@ -105,21 +105,3 @@ int __stdcall DllMain(HANDLE hInst,DWORD ul_reason_being_called,LPVOID lpReserve return TRUE; } -#elif defined(WINDOWS) - -/**************************************************************************** -** This routine is called by LIBSTART.ASM at module load time. All it -** does in this sample is remember the DLL module handle. The module -** handle is needed if you want to do things like load stuff from the -** resource file (for instance string resources). -****************************************************************************/ - -int _export FAR PASCAL libmain(HANDLE hModule,short cbHeapSize, - UCHAR FAR *lszCmdLine) -{ - s_hModule = hModule; - libmysql_init(); - return TRUE; -} - -#endif diff --git a/libmysql/libmysql.c b/libmysql/libmysql.c index 68813937fb6..7af9c5a6525 100644 --- a/libmysql/libmysql.c +++ b/libmysql/libmysql.c @@ -34,7 +34,7 @@ #ifdef HAVE_PWD_H #include #endif -#if !defined(MSDOS) && !defined(__WIN__) +#if !defined(__WIN__) #include #include #include @@ -45,7 +45,7 @@ #ifdef HAVE_SYS_SELECT_H #include #endif -#endif /* !defined(MSDOS) && !defined(__WIN__) */ +#endif /* !defined(__WIN__) */ #ifdef HAVE_POLL #include #endif @@ -74,7 +74,7 @@ ulong max_allowed_packet= 1024L*1024L*1024L; my_bool net_flush(NET *net); #endif -#if defined(MSDOS) || defined(__WIN__) +#if defined(__WIN__) /* socket_errno is defined in my_global.h for all platforms */ #define perror(A) #else @@ -128,31 +128,29 @@ int STDCALL mysql_server_init(int argc __attribute__((unused)), init_client_errs(); if (!mysql_port) { + char *env; + struct servent *serv_ptr __attribute__((unused)); + mysql_port = MYSQL_PORT; -#ifndef MSDOS - { - struct servent *serv_ptr __attribute__((unused)); - char *env; - /* - if builder specifically requested a default port, use that - (even if it coincides with our factory default). - only if they didn't do we check /etc/services (and, failing - on that, fall back to the factory default of 3306). - either default can be overridden by the environment variable - MYSQL_TCP_PORT, which in turn can be overridden with command - line options. - */ + /* + if builder specifically requested a default port, use that + (even if it coincides with our factory default). + only if they didn't do we check /etc/services (and, failing + on that, fall back to the factory default of 3306). + either default can be overridden by the environment variable + MYSQL_TCP_PORT, which in turn can be overridden with command + line options. + */ #if MYSQL_PORT_DEFAULT == 0 - if ((serv_ptr = getservbyname("mysql", "tcp"))) - mysql_port = (uint) ntohs((ushort) serv_ptr->s_port); -#endif - if ((env = getenv("MYSQL_TCP_PORT"))) - mysql_port =(uint) atoi(env); - } + if ((serv_ptr= getservbyname("mysql", "tcp"))) + mysql_port= (uint) ntohs((ushort) serv_ptr->s_port); #endif + if ((env= getenv("MYSQL_TCP_PORT"))) + mysql_port=(uint) atoi(env); } + if (!mysql_unix_port) { char *env; @@ -479,7 +477,7 @@ struct passwd *getpwuid(uid_t); char* getlogin(void); #endif -#if !defined(MSDOS) && ! defined(VMS) && !defined(__WIN__) +#if !defined(VMS) && !defined(__WIN__) void read_user_name(char *name) { @@ -509,7 +507,7 @@ void read_user_name(char *name) DBUG_VOID_RETURN; } -#else /* If MSDOS || VMS */ +#else /* If Windows || VMS */ void read_user_name(char *name) { -- cgit v1.2.1 From 6420d6dc4a819cf5304b69d9270da0fcdbfb60ba Mon Sep 17 00:00:00 2001 From: Davi Arnaut Date: Thu, 15 Jul 2010 08:26:38 -0300 Subject: WL#5486: Remove code for unsupported platforms Remove VMS specific code. --- libmysql/libmysql.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'libmysql') diff --git a/libmysql/libmysql.c b/libmysql/libmysql.c index 7af9c5a6525..e4f01dad88b 100644 --- a/libmysql/libmysql.c +++ b/libmysql/libmysql.c @@ -477,7 +477,7 @@ struct passwd *getpwuid(uid_t); char* getlogin(void); #endif -#if !defined(VMS) && !defined(__WIN__) +#if !defined(__WIN__) void read_user_name(char *name) { @@ -507,7 +507,7 @@ void read_user_name(char *name) DBUG_VOID_RETURN; } -#else /* If Windows || VMS */ +#else /* If Windows */ void read_user_name(char *name) { -- cgit v1.2.1