diff options
author | Daniel Black <danielgb@au.ibm.com> | 2018-02-25 15:25:54 +1100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2018-02-25 15:25:54 +1100 |
commit | 0805a9565f09a36104a420d9e229e44b1eea8879 (patch) | |
tree | 5c5dbf942479c2b7349f1b4505768ddf5a2f8b8d /mysys | |
parent | 3188131b15c26509e4df3c4b15972d07a20be8bd (diff) | |
parent | 8936b175106a3fdfc560e9d33aa58a6372084c5f (diff) | |
download | mariadb-git-0805a9565f09a36104a420d9e229e44b1eea8879.tar.gz |
Merge branch '10.3' into 10.2-MDEV-10814-dont-dump-query-cache
Diffstat (limited to 'mysys')
43 files changed, 409 insertions, 266 deletions
diff --git a/mysys/CMakeLists.txt b/mysys/CMakeLists.txt index 265f3aa86b7..c911cd064cd 100644 --- a/mysys/CMakeLists.txt +++ b/mysys/CMakeLists.txt @@ -36,7 +36,8 @@ SET(MYSYS_SOURCES array.c charset-def.c charset.c checksum.c my_default.c string.c thr_alarm.c thr_lock.c thr_mutex.c thr_rwlock.c thr_timer.c tree.c typelib.c base64.c my_memmem.c - my_getpagesize.c + my_getpagesize.c + guess_malloc_library.c lf_alloc-pin.c lf_dynarray.c lf_hash.c safemalloc.c my_new.cc my_getncpus.c my_safehash.c my_chmod.c my_rnd.c diff --git a/mysys/file_logger.c b/mysys/file_logger.c index 078286cd7d0..35a077c4391 100644 --- a/mysys/file_logger.c +++ b/mysys/file_logger.c @@ -172,7 +172,7 @@ int logger_vprintf(LOGGER_HANDLE *log, const char* fmt, va_list ap) if (n_bytes >= sizeof(cvtbuf)) n_bytes= sizeof(cvtbuf) - 1; - result= my_write(log->file, (uchar *) cvtbuf, n_bytes, MYF(0)); + result= (int)my_write(log->file, (uchar *) cvtbuf, n_bytes, MYF(0)); exit: flogger_mutex_unlock(&log->lock); @@ -196,7 +196,7 @@ int logger_write(LOGGER_HANDLE *log, const char *buffer, size_t size) goto exit; /* Log rotation needed but failed */ } - result= my_write(log->file, (uchar *) buffer, size, MYF(0)); + result= (int)my_write(log->file, (uchar *) buffer, size, MYF(0)); exit: flogger_mutex_unlock(&log->lock); diff --git a/mysys/get_password.c b/mysys/get_password.c index 8a507d94e9b..2b63a686d07 100644 --- a/mysys/get_password.c +++ b/mysys/get_password.c @@ -64,7 +64,6 @@ char *get_tty_password(const char *opt_message) { char to[80]; char *pos=to,*end=to+sizeof(to)-1; - int i=0; DBUG_ENTER("get_tty_password"); _cputs(opt_message ? opt_message : "Enter password: "); for (;;) diff --git a/mysys/guess_malloc_library.c b/mysys/guess_malloc_library.c new file mode 100644 index 00000000000..ed86ae0679c --- /dev/null +++ b/mysys/guess_malloc_library.c @@ -0,0 +1,65 @@ +/* Copyright (c) 2002, 2015, Oracle and/or its affiliates. + Copyright (c) 2012, 2017, MariaDB Corporation. + + 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 */ + +/* guess_malloc_library() deduces, to the best of its ability, + the currently used malloc library and its version */ + +#include <stddef.h> +#include "my_global.h" +#include <m_string.h> + +typedef const char* (*tc_version_type)(int*, int*, const char**); +typedef int (*mallctl_type)(const char*, void*, size_t*, void*, size_t); + +char *guess_malloc_library() +{ + tc_version_type tc_version_func; + mallctl_type mallctl_func; +#ifndef HAVE_DLOPEN + return (char*) MALLOC_LIBRARY; +#else + static char buf[128]; + + if (strcmp(MALLOC_LIBRARY, "system") != 0) + { + return (char*) MALLOC_LIBRARY; + } + + /* tcmalloc */ + tc_version_func= (tc_version_type) dlsym(RTLD_DEFAULT, "tc_version"); + if (tc_version_func) + { + int major, minor; + const char* ver_str = tc_version_func(&major, &minor, NULL); + strxnmov(buf, sizeof(buf)-1, "tcmalloc ", ver_str, NULL); + return buf; + } + + /* jemalloc */ + mallctl_func= (mallctl_type) dlsym(RTLD_DEFAULT, "mallctl"); + if (mallctl_func) + { + char *ver; + size_t len = sizeof(ver); + mallctl_func("version", &ver, &len, NULL, 0); + strxnmov(buf, sizeof(buf)-1, "jemalloc ", ver, NULL); + return buf; + } + + return (char*) MALLOC_LIBRARY; +#endif +} + diff --git a/mysys/hash.c b/mysys/hash.c index 57242735d99..d9952afe318 100644 --- a/mysys/hash.c +++ b/mysys/hash.c @@ -380,7 +380,7 @@ static int hashcmp(const HASH *hash, HASH_LINK *pos, const uchar *key, my_bool my_hash_insert(HASH *info, const uchar *record) { int flag; - uint idx, halfbuff, first_index; + size_t idx, halfbuff, first_index; size_t length; my_hash_value_type current_hash_nr, UNINIT_VAR(rec_hash_nr), UNINIT_VAR(rec2_hash_nr); diff --git a/mysys/lf_alloc-pin.c b/mysys/lf_alloc-pin.c index bf2b8a12846..4e4917962ab 100644 --- a/mysys/lf_alloc-pin.c +++ b/mysys/lf_alloc-pin.c @@ -161,7 +161,7 @@ LF_PINS *lf_pinbox_get_pins(LF_PINBOX *pinbox) pinstack_top_ver is 32 bits; 16 low bits are the index in the array, to the first element of the list. 16 high bits are a version (every time the 16 low bits are updated, the 16 high bits are - incremented). Versioniong prevents the ABA problem. + incremented). Versioning prevents the ABA problem. */ top_ver= pinbox->pinstack_top_ver; do @@ -430,7 +430,7 @@ static void alloc_free(uchar *first, { anext_node(last)= tmp.node; } while (!my_atomic_casptr((void **)(char *)&allocator->top, - (void **)&tmp.ptr, first) && LF_BACKOFF); + (void **)&tmp.ptr, first) && LF_BACKOFF()); } /* @@ -501,7 +501,7 @@ void *lf_alloc_new(LF_PINS *pins) { node= allocator->top; lf_pin(pins, 0, node); - } while (node != allocator->top && LF_BACKOFF); + } while (node != allocator->top && LF_BACKOFF()); if (!node) { node= (void *)my_malloc(allocator->element_size, MYF(MY_WME)); diff --git a/mysys/lf_hash.c b/mysys/lf_hash.c index 430f1007f30..a7c07679993 100644 --- a/mysys/lf_hash.c +++ b/mysys/lf_hash.c @@ -86,12 +86,12 @@ typedef struct { 1 - error (callbck returned 1) */ static int l_find(LF_SLIST * volatile *head, CHARSET_INFO *cs, uint32 hashnr, - const uchar *key, uint keylen, CURSOR *cursor, LF_PINS *pins, + const uchar *key, size_t keylen, CURSOR *cursor, LF_PINS *pins, my_hash_walk_action callback) { uint32 cur_hashnr; const uchar *cur_key; - uint cur_keylen; + size_t cur_keylen; intptr link; DBUG_ASSERT(!cs || !callback); /* should not be set both */ @@ -102,7 +102,7 @@ retry: do { /* PTR() isn't necessary below, head is a dummy node */ cursor->curr= (LF_SLIST *)(*cursor->prev); lf_pin(pins, 1, cursor->curr); - } while (*cursor->prev != (intptr)cursor->curr && LF_BACKOFF); + } while (*cursor->prev != (intptr)cursor->curr && LF_BACKOFF()); for (;;) { @@ -117,7 +117,7 @@ retry: link= cursor->curr->link; cursor->next= PTR(link); lf_pin(pins, 0, cursor->next); - } while (link != cursor->curr->link && LF_BACKOFF); + } while (link != cursor->curr->link && LF_BACKOFF()); if (!DELETED(link)) { @@ -145,7 +145,7 @@ retry: and remove this deleted node */ if (my_atomic_casptr((void **) cursor->prev, - (void **) &cursor->curr, cursor->next) && LF_BACKOFF) + (void **) &cursor->curr, cursor->next) && LF_BACKOFF()) lf_alloc_free(pins, cursor->curr); else goto retry; diff --git a/mysys/ma_dyncol.c b/mysys/ma_dyncol.c index 125b3a4632d..0085c375aa1 100644 --- a/mysys/ma_dyncol.c +++ b/mysys/ma_dyncol.c @@ -3818,6 +3818,58 @@ end: DBUG_RETURN(rc); } +static +my_bool dynstr_append_json_quoted(DYNAMIC_STRING *str, + const char *append, size_t len) +{ + size_t additional= ((str->alloc_increment && str->alloc_increment > 6) ? + str->alloc_increment : + 10); + size_t lim= additional; + size_t i; + if (dynstr_realloc(str, len + additional + 2)) + return TRUE; + str->str[str->length++]= '"'; + for (i= 0; i < len; i++) + { + register char c= append[i]; + if (unlikely(((uchar)c) <= 0x1F)) + { + if (lim < 5) + { + if (dynstr_realloc(str, additional)) + return TRUE; + lim+= additional; + } + lim-= 5; + str->str[str->length++]= '\\'; + str->str[str->length++]= 'u'; + str->str[str->length++]= '0'; + str->str[str->length++]= '0'; + str->str[str->length++]= (c < 0x10 ? '0' : '1'); + c%= 0x10; + str->str[str->length++]= (c < 0xA ? '0' + c : 'A' + (c - 0xA)); + } + else + { + if (c == '"' || c == '\\') + { + if (!lim) + { + if (dynstr_realloc(str, additional)) + return TRUE; + lim= additional; + } + lim--; + str->str[str->length++]= '\\'; + } + str->str[str->length++]= c; + } + } + str->str[str->length++]= '"'; + return FALSE; +} + enum enum_dyncol_func_result mariadb_dyncol_val_str(DYNAMIC_STRING *str, DYNAMIC_COLUMN_VALUE *val, @@ -3883,7 +3935,10 @@ mariadb_dyncol_val_str(DYNAMIC_STRING *str, DYNAMIC_COLUMN_VALUE *val, return ER_DYNCOL_RESOURCE; } if (quote) - rc= dynstr_append_quoted(str, from, len, quote); + if (quote == DYNCOL_JSON_ESC) + rc= dynstr_append_json_quoted(str, from, len); + else + rc= dynstr_append_quoted(str, from, len, quote); else rc= dynstr_append_mem(str, from, len); if (alloc) @@ -4183,8 +4238,8 @@ mariadb_dyncol_json_internal(DYNAMIC_COLUMN *str, DYNAMIC_STRING *json, } else { - if ((rc= mariadb_dyncol_val_str(json, &val, - &my_charset_utf8_general_ci, '"')) < 0) + if ((rc= mariadb_dyncol_val_str(json, &val, DYNCOL_UTF, DYNCOL_JSON_ESC)) + < 0) goto err; } } diff --git a/mysys/mf_iocache.c b/mysys/mf_iocache.c index a52ea2c5c40..d63547e0936 100644 --- a/mysys/mf_iocache.c +++ b/mysys/mf_iocache.c @@ -115,6 +115,7 @@ init_functions(IO_CACHE* info) DBUG_ASSERT(!(info->myflags & MY_ENCRYPT)); info->read_function = info->share ? _my_b_cache_read_r : _my_b_cache_read; info->write_function = info->share ? _my_b_cache_write_r : _my_b_cache_write; + info->myflags&= ~MY_FULL_IO; break; case TYPE_NOT_SET: DBUG_ASSERT(0); @@ -271,7 +272,7 @@ int init_io_cache(IO_CACHE *info, File file, size_t cachesize, else { /* Clear mutex so that safe_mutex will notice that it's not initialized */ - bzero((char*) &info->append_buffer_lock, sizeof(info)); + bzero((char*) &info->append_buffer_lock, sizeof(info->append_buffer_lock)); } #endif @@ -455,6 +456,8 @@ my_bool reinit_io_cache(IO_CACHE *info, enum cache_type type, { info->read_end=info->write_pos; info->end_of_file=my_b_tell(info); + /* Ensure we will read all data */ + info->myflags|= MY_FULL_IO; /* Trigger a new seek only if we have a valid file handle. @@ -469,6 +472,7 @@ my_bool reinit_io_cache(IO_CACHE *info, enum cache_type type, info->seek_not_done=1; } info->end_of_file = ~(my_off_t) 0; + info->myflags&= ~MY_FULL_IO; } pos=info->request_pos+(seek_offset-info->pos_in_file); if (type == WRITE_CACHE) @@ -508,7 +512,7 @@ my_bool reinit_io_cache(IO_CACHE *info, enum cache_type type, info->read_end= info->buffer; _my_b_encr_read(info, 0, 0); /* prefill the buffer */ info->write_pos= info->read_pos; - info->pos_in_file+= info->buffer_length; + info->seek_not_done=1; } } else @@ -553,7 +557,7 @@ int _my_b_read(IO_CACHE *info, uchar *Buffer, size_t Count) } res= info->read_function(info, Buffer, Count); if (res && info->error >= 0) - info->error+= left_length; /* update number or read bytes */ + info->error+= (int)left_length; /* update number or read bytes */ return res; } @@ -1917,13 +1921,12 @@ int my_b_flush_io_cache(IO_CACHE *info, int need_append_buffer_lock) { if (append_cache) { - if (mysql_file_write(info->file, info->write_buffer, length, info->myflags | MY_NABP)) + { info->error= -1; - else - info->error= 0; - + DBUG_RETURN(-1); + } info->end_of_file+= info->write_pos - info->append_read_pos; info->append_read_pos= info->write_buffer; DBUG_ASSERT(info->end_of_file == mysql_file_tell(info->file, MYF(0))); diff --git a/mysys/mf_iocache2.c b/mysys/mf_iocache2.c index 2499094037d..ef163ee24d3 100644 --- a/mysys/mf_iocache2.c +++ b/mysys/mf_iocache2.c @@ -249,18 +249,16 @@ my_off_t my_b_filelength(IO_CACHE *info) } -size_t +my_bool my_b_write_backtick_quote(IO_CACHE *info, const char *str, size_t len) { const uchar *start; const uchar *p= (const uchar *)str; const uchar *end= p + len; size_t count; - size_t total= 0; if (my_b_write(info, (uchar *)"`", 1)) - return (size_t)-1; - ++total; + return 1; for (;;) { start= p; @@ -268,35 +266,32 @@ my_b_write_backtick_quote(IO_CACHE *info, const char *str, size_t len) ++p; count= p - start; if (count && my_b_write(info, start, count)) - return (size_t)-1; - total+= count; + return 1; if (p >= end) break; if (my_b_write(info, (uchar *)"``", 2)) - return (size_t)-1; - total+= 2; + return 1; ++p; } - if (my_b_write(info, (uchar *)"`", 1)) - return (size_t)-1; - ++total; - return total; + return (my_b_write(info, (uchar *)"`", 1)); } /* Simple printf version. Supports '%s', '%d', '%u', "%ld" and "%lu" - Used for logging in MySQL - returns number of written character, or (size_t) -1 on error + Used for logging in MariaDB + + @return 0 ok + 1 error */ -size_t my_b_printf(IO_CACHE *info, const char* fmt, ...) +my_bool my_b_printf(IO_CACHE *info, const char* fmt, ...) { size_t result; va_list args; va_start(args,fmt); result=my_b_vprintf(info, fmt, args); va_end(args); - return result; + return result == (size_t) -1; } diff --git a/mysys/mf_keycache.c b/mysys/mf_keycache.c index 2f0f2bf05c0..edf8cd3be8a 100644 --- a/mysys/mf_keycache.c +++ b/mysys/mf_keycache.c @@ -2429,7 +2429,7 @@ restart: The call is thread safe because only the current thread might change the block->hash_link value */ - error= my_pwrite(block->hash_link->file, + error= (int)my_pwrite(block->hash_link->file, block->buffer + block->offset, block->length - block->offset, block->hash_link->diskpos + block->offset, @@ -2674,7 +2674,7 @@ static void read_block_primary(SIMPLE_KEY_CACHE_CB *keycache, else { block->status|= BLOCK_READ; - block->length= got_length; + block->length= (uint)got_length; /* Do not set block->offset here. If this block is marked BLOCK_CHANGED later, we want to flush only the modified part. So @@ -3809,7 +3809,7 @@ static int flush_cached_blocks(SIMPLE_KEY_CACHE_CB *keycache, (BLOCK_READ | BLOCK_IN_FLUSH | BLOCK_CHANGED | BLOCK_IN_USE)); block->status|= BLOCK_IN_FLUSHWRITE; keycache_pthread_mutex_unlock(&keycache->cache_lock); - error= my_pwrite(file, block->buffer + block->offset, + error= (int)my_pwrite(file, block->buffer + block->offset, block->length - block->offset, block->hash_link->diskpos + block->offset, MYF(MY_NABP | MY_WAIT_IF_FULL)); diff --git a/mysys/my_access.c b/mysys/my_access.c index 75774240406..0f3263a79c3 100644 --- a/mysys/my_access.c +++ b/mysys/my_access.c @@ -38,7 +38,7 @@ int my_access(const char *path, int amode) attributes = GetFileAttributes(path); if (attributes == INVALID_FILE_ATTRIBUTES || - (attributes & FILE_ATTRIBUTE_READONLY) && (amode & W_OK)) + ((attributes & FILE_ATTRIBUTE_READONLY) && (amode & W_OK))) { my_errno= errno= EACCES; return -1; diff --git a/mysys/my_addr_resolve.c b/mysys/my_addr_resolve.c index 83716bf11e1..84bff47d1a9 100644 --- a/mysys/my_addr_resolve.c +++ b/mysys/my_addr_resolve.c @@ -34,13 +34,6 @@ static const char *strip_path(const char *s) return prev; } -#if defined(HAVE_LINK_H) && defined(HAVE_DLOPEN) -#include <link.h> -static ptrdiff_t offset= 0; -#else -#define offset 0 -#endif - /* The following is very much single-threaded code and it's only supposed to be used on shutdown or for a crash report @@ -56,6 +49,13 @@ static ptrdiff_t offset= 0; static bfd *bfdh= 0; static asymbol **symtable= 0; +#if defined(HAVE_LINK_H) && defined(HAVE_DLOPEN) +#include <link.h> +static ElfW(Addr) offset= 0; +#else +#define offset 0 +#endif + /** finds a file name, a line number, and a function name corresponding to addr. @@ -145,10 +145,52 @@ err: #include <m_string.h> #include <ctype.h> +#include <sys/wait.h> static int in[2], out[2]; -static int initialized= 0; +static pid_t pid; +static char addr2line_binary[1024]; static char output[1024]; + +int start_addr2line_fork(const char *binary_path) +{ + + if (pid > 0) + { + /* Don't leak FDs */ + close(in[1]); + close(out[0]); + /* Don't create zombie processes. */ + waitpid(pid, NULL, 0); + } + + if (pipe(in) < 0) + return 1; + if (pipe(out) < 0) + return 1; + + pid = fork(); + if (pid == -1) + return 1; + + if (!pid) /* child */ + { + dup2(in[0], 0); + dup2(out[1], 1); + close(in[0]); + close(in[1]); + close(out[0]); + close(out[1]); + execlp("addr2line", "addr2line", "-C", "-f", "-e", binary_path, NULL); + exit(1); + } + + close(in[0]); + close(out[1]); + + return 0; +} + int my_addr_resolve(void *ptr, my_addr_loc *loc) { char input[32]; @@ -156,69 +198,88 @@ int my_addr_resolve(void *ptr, my_addr_loc *loc) ssize_t total_bytes_read = 0; ssize_t extra_bytes_read = 0; + ssize_t parsed = 0; fd_set set; struct timeval timeout; int filename_start = -1; int line_number_start = -1; - ssize_t i; - FD_ZERO(&set); - FD_SET(out[0], &set); + Dl_info info; + void *offset; + + if (!dladdr(ptr, &info)) + return 1; + if (strcmp(addr2line_binary, info.dli_fname)) + { + /* We use dli_fname in case the path is longer than the length of our static + string. We don't want to allocate anything dynamicaly here as we are in + a "crashed" state. */ + if (start_addr2line_fork(info.dli_fname)) + { + addr2line_binary[0] = '\0'; + return 2; + } + /* Save result for future comparisons. */ + strnmov(addr2line_binary, info.dli_fname, sizeof(addr2line_binary)); + } + offset = info.dli_fbase; len= my_snprintf(input, sizeof(input), "%p\n", ptr - offset); if (write(in[1], input, len) <= 0) - return 1; + return 3; - /* 10 ms should be plenty of time for addr2line to issue a response. */ + FD_ZERO(&set); + FD_SET(out[0], &set); + + /* 100 ms should be plenty of time for addr2line to issue a response. */ timeout.tv_sec = 0; - timeout.tv_usec = 10000; + timeout.tv_usec = 100000; /* Read in a loop till all the output from addr2line is complete. */ - while (select(out[0] + 1, &set, NULL, NULL, &timeout) > 0) + while (parsed == total_bytes_read && + select(out[0] + 1, &set, NULL, NULL, &timeout) > 0) { extra_bytes_read= read(out[0], output + total_bytes_read, sizeof(output) - total_bytes_read); if (extra_bytes_read < 0) - return 2; + return 4; /* Timeout or max bytes read. */ if (extra_bytes_read == 0) break; total_bytes_read += extra_bytes_read; - } - - /* Failed starting addr2line. */ - if (total_bytes_read == 0) - return 3; - /* Go through the addr2line response and get the required data. - The response is structured in 2 lines. The first line contains the function - name, while the second one contains <filename>:<line number> */ - for (i = 0; i < total_bytes_read; i++) { - if (output[i] == '\n') { - filename_start = i + 1; - output[i] = '\0'; - } - if (filename_start != -1 && output[i] == ':') { - line_number_start = i + 1; - output[i] = '\0'; - } - if (line_number_start != -1) { - loc->line= atoi(output + line_number_start); - break; + /* Go through the addr2line response and get the required data. + The response is structured in 2 lines. The first line contains the function + name, while the second one contains <filename>:<line number> */ + for (; parsed < total_bytes_read; parsed++) + { + if (output[parsed] == '\n') + { + filename_start = parsed + 1; + output[parsed] = '\0'; + } + if (filename_start != -1 && output[parsed] == ':') + { + line_number_start = parsed + 1; + output[parsed] = '\0'; + break; + } } } + /* Response is malformed. */ if (filename_start == -1 || line_number_start == -1) - return 4; + return 5; loc->func= output; loc->file= output + filename_start; + loc->line= atoi(output + line_number_start); /* Addr2line was unable to extract any meaningful information. */ if (strcmp(loc->file, "??") == 0) - return 5; + return 6; loc->file= strip_path(loc->file); @@ -227,41 +288,6 @@ int my_addr_resolve(void *ptr, my_addr_loc *loc) const char *my_addr_resolve_init() { - if (!initialized) - { - pid_t pid; - -#if defined(HAVE_LINK_H) && defined(HAVE_DLOPEN) - struct link_map *lm = (struct link_map*) dlopen(0, RTLD_NOW); - if (lm) - offset= lm->l_addr; -#endif - - if (pipe(in) < 0) - return "pipe(in)"; - if (pipe(out) < 0) - return "pipe(out)"; - - pid = fork(); - if (pid == -1) - return "fork"; - - if (!pid) /* child */ - { - dup2(in[0], 0); - dup2(out[1], 1); - close(in[0]); - close(in[1]); - close(out[0]); - close(out[1]); - execlp("addr2line", "addr2line", "-C", "-f", "-e", my_progname, NULL); - exit(1); - } - - close(in[0]); - close(out[1]); - initialized= 1; - } return 0; } #endif diff --git a/mysys/my_alloc.c b/mysys/my_alloc.c index 3df73127998..7139466be17 100644 --- a/mysys/my_alloc.c +++ b/mysys/my_alloc.c @@ -26,12 +26,15 @@ #define MALLOC_FLAG(A) ((A & 1) ? MY_THREAD_SPECIFIC : 0) +#define TRASH_MEM(X) TRASH_FREE(((char*)(X) + ((X)->size-(X)->left)), (X)->left) + /* Initialize memory root SYNOPSIS init_alloc_root() mem_root - memory root to initialize + name - name of memroot (for debugging) block_size - size of chunks (blocks) used for memory allocation (It is external size of chunk i.e. it should include memory required for internal structures, thus it @@ -51,13 +54,13 @@ Because of this, we store in MY_THREAD_SPECIFIC as bit 1 in block_size */ -void init_alloc_root(MEM_ROOT *mem_root, size_t block_size, +void init_alloc_root(MEM_ROOT *mem_root, const char *name, size_t block_size, size_t pre_alloc_size __attribute__((unused)), myf my_flags) { DBUG_ENTER("init_alloc_root"); - DBUG_PRINT("enter",("root: %p prealloc: %zu", mem_root, - pre_alloc_size)); + DBUG_PRINT("enter",("root: %p name: %s prealloc: %zu", mem_root, + name, pre_alloc_size)); mem_root->free= mem_root->used= mem_root->pre_alloc= 0; mem_root->min_malloc= 32; @@ -69,18 +72,20 @@ void init_alloc_root(MEM_ROOT *mem_root, size_t block_size, mem_root->block_num= 4; /* We shift this with >>2 */ mem_root->first_block_usage= 0; mem_root->total_alloc= 0; + mem_root->name= name; #if !(defined(HAVE_valgrind) && defined(EXTRA_DEBUG)) if (pre_alloc_size) { if ((mem_root->free= mem_root->pre_alloc= - (USED_MEM*) my_malloc(pre_alloc_size+ ALIGN_SIZE(sizeof(USED_MEM)), - MYF(my_flags)))) + (USED_MEM*) my_malloc(pre_alloc_size + ALIGN_SIZE(sizeof(USED_MEM)), + MYF(my_flags)))) { mem_root->free->size= pre_alloc_size+ALIGN_SIZE(sizeof(USED_MEM)); mem_root->total_alloc= pre_alloc_size+ALIGN_SIZE(sizeof(USED_MEM)); mem_root->free->left= pre_alloc_size; mem_root->free->next= 0; + TRASH_MEM(mem_root->free); } } #endif @@ -152,6 +157,7 @@ void reset_root_defaults(MEM_ROOT *mem_root, size_t block_size, mem->left= pre_alloc_size; mem->next= *prev; *prev= mem_root->pre_alloc= mem; + TRASH_MEM(mem); } else { @@ -172,7 +178,7 @@ void *alloc_root(MEM_ROOT *mem_root, size_t length) #if defined(HAVE_valgrind) && defined(EXTRA_DEBUG) reg1 USED_MEM *next; DBUG_ENTER("alloc_root"); - DBUG_PRINT("enter",("root: %p", mem_root)); + DBUG_PRINT("enter",("root: %p name: %s", mem_root, mem_root->name)); DBUG_ASSERT(alloc_root_inited(mem_root)); @@ -207,7 +213,7 @@ void *alloc_root(MEM_ROOT *mem_root, size_t length) reg1 USED_MEM *next= 0; reg2 USED_MEM **prev; DBUG_ENTER("alloc_root"); - DBUG_PRINT("enter",("root: %p", mem_root)); + DBUG_PRINT("enter",("root: %p name: %s", mem_root, mem_root->name)); DBUG_ASSERT(alloc_root_inited(mem_root)); DBUG_EXECUTE_IF("simulate_out_of_memory", @@ -255,6 +261,7 @@ void *alloc_root(MEM_ROOT *mem_root, size_t length) next->size= get_size; next->left= get_size-ALIGN_SIZE(sizeof(USED_MEM)); *prev=next; + TRASH_MEM(next); } point= (uchar*) ((char*) next+ (next->size-next->left)); @@ -298,6 +305,10 @@ void *multi_alloc_root(MEM_ROOT *root, ...) char **ptr, *start, *res; size_t tot_length, length; DBUG_ENTER("multi_alloc_root"); + /* + We don't need to do DBUG_PRINT here as it will be done when alloc_root + is called + */ va_start(args, root); tot_length= 0; @@ -323,9 +334,9 @@ void *multi_alloc_root(MEM_ROOT *root, ...) DBUG_RETURN((void*) start); } -#define TRASH_MEM(X) TRASH(((char*)(X) + ((X)->size-(X)->left)), (X)->left) -/* Mark all data in blocks free for reusage */ +#if !(defined(HAVE_valgrind) && defined(EXTRA_DEBUG)) +/** Mark all data in blocks free for reusage */ static inline void mark_blocks_free(MEM_ROOT* root) { @@ -355,6 +366,7 @@ static inline void mark_blocks_free(MEM_ROOT* root) root->first_block_usage= 0; root->block_num= 4; } +#endif /* @@ -380,7 +392,8 @@ void free_root(MEM_ROOT *root, myf MyFlags) { reg1 USED_MEM *next,*old; DBUG_ENTER("free_root"); - DBUG_PRINT("enter",("root: %p flags: %u", root, (uint) MyFlags)); + DBUG_PRINT("enter",("root: %p name: %s flags: %u", root, root->name, + (uint) MyFlags)); #if !(defined(HAVE_valgrind) && defined(EXTRA_DEBUG)) /* diff --git a/mysys/my_atomic_writes.c b/mysys/my_atomic_writes.c index 0b54a207713..7f1e353c121 100644 --- a/mysys/my_atomic_writes.c +++ b/mysys/my_atomic_writes.c @@ -259,7 +259,7 @@ static my_bool shannon_has_atomic_write(File file, int page_size) ************************************************************************/ /* - Initalize automic write sub systems. + Initialize automic write sub systems. Checks if we have any devices that supports atomic write */ diff --git a/mysys/my_bitmap.c b/mysys/my_bitmap.c index a0c1a23d63c..b6963739613 100644 --- a/mysys/my_bitmap.c +++ b/mysys/my_bitmap.c @@ -166,6 +166,9 @@ static inline uint get_first_set(my_bitmap_map value, uint word_pos) return MY_BIT_NONE; /* Impossible */ } +/* + Initialize a bitmap object. All bits will be set to zero +*/ my_bool my_bitmap_init(MY_BITMAP *map, my_bitmap_map *buf, uint n_bits, my_bool thread_safe) diff --git a/mysys/my_compare.c b/mysys/my_compare.c index 5ba1b409abb..4d384936a55 100644 --- a/mysys/my_compare.c +++ b/mysys/my_compare.c @@ -20,8 +20,8 @@ #include <my_compare.h> #include <my_sys.h> -int ha_compare_text(CHARSET_INFO *charset_info, const uchar *a, uint a_length, - const uchar *b, uint b_length, my_bool part_key) +int ha_compare_text(CHARSET_INFO *charset_info, const uchar *a, size_t a_length, + const uchar *b, size_t b_length, my_bool part_key) { if (!part_key) return charset_info->coll->strnncollsp(charset_info, a, a_length, diff --git a/mysys/my_conio.c b/mysys/my_conio.c index 0af5706cace..21f30bd9b67 100644 --- a/mysys/my_conio.c +++ b/mysys/my_conio.c @@ -47,7 +47,7 @@ static HANDLE my_coninpfh= 0; /* console input */ static int my_pthread_auto_mutex_lock(HANDLE* ph, const char* name, int id, int time) { - int res; + DWORD res; char tname[FN_REFLEN]; sprintf(tname, "%s-%08X", name, id); @@ -203,7 +203,7 @@ char* my_cgets(char *buffer, size_t clen, size_t* plen) if (*plen > 0 && buffer[*plen - 1] == '\r') { char tmp[3]; - int tmplen= sizeof(tmp); + DWORD tmplen= (DWORD)sizeof(tmp); *plen= *plen - 1; /* read /n left in the buffer */ diff --git a/mysys/my_context.c b/mysys/my_context.c index cf10738bdbd..5423f59d19b 100644 --- a/mysys/my_context.c +++ b/mysys/my_context.c @@ -707,7 +707,7 @@ my_context_continue(struct my_context *c) { /* This seems to be a common trick to run ConvertThreadToFiber() only on the - first occurence in a thread, in a way that works on multiple Windows + first occurrence in a thread, in a way that works on multiple Windows versions. */ void *current_fiber= GetCurrentFiber(); diff --git a/mysys/my_default.c b/mysys/my_default.c index 37f6d2bfbbf..dc8523576c6 100644 --- a/mysys/my_default.c +++ b/mysys/my_default.c @@ -1,4 +1,5 @@ -/* Copyright (c) 2000, 2011, Oracle and/or its affiliates. All rights reserved. +/* Copyright (c) 2000, 2017, Oracle and/or its affiliates. All rights reserved. + Copyright (c) 2011, 2018, MariaDB Corporation 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 @@ -233,7 +234,7 @@ int my_search_option_files(const char *conf_file, int *argc, char ***argv, (char **) &my_defaults_group_suffix); if (! my_defaults_group_suffix) - my_defaults_group_suffix= getenv(STRINGIFY_ARG(DEFAULT_GROUP_SUFFIX_ENV)); + my_defaults_group_suffix= getenv("MYSQL_GROUP_SUFFIX"); if (forced_extra_defaults && !defaults_already_read) { @@ -487,8 +488,7 @@ int load_defaults(const char *conf_file, const char **groups, easily command line options override options in configuration files NOTES - In case of fatal error, the function will print a warning and do - exit(1) + In case of fatal error, the function will print a warning and returns 2 To free used memory one should call free_defaults() with the argument that was put in *argv @@ -519,7 +519,7 @@ int my_load_defaults(const char *conf_file, const char **groups, uint args_sep= my_getopt_use_args_separator ? 1 : 0; DBUG_ENTER("load_defaults"); - init_alloc_root(&alloc, 512, 0, MYF(0)); + init_alloc_root(&alloc, "my_load_defaults", 512, 0, MYF(0)); if ((dirs= init_default_directories(&alloc)) == NULL) goto err; /* @@ -641,8 +641,7 @@ int my_load_defaults(const char *conf_file, const char **groups, err: fprintf(stderr,"Fatal error in defaults handling. Program aborted\n"); - exit(1); - return 0; /* Keep compiler happy */ + return 2; } @@ -1043,7 +1042,7 @@ void my_print_default_files(const char *conf_file) { const char **dirs; MEM_ROOT alloc; - init_alloc_root(&alloc, 512, 0, MYF(0)); + init_alloc_root(&alloc, "my_print_defaults", 512, 0, MYF(0)); if ((dirs= init_default_directories(&alloc)) == NULL) { @@ -1185,7 +1184,7 @@ static const char **init_default_directories(MEM_ROOT *alloc) { errors += add_directory(alloc, fname_buffer, dirs); - strncat(fname_buffer, "/data", sizeof(fname_buffer)); + strcat_s(fname_buffer, sizeof(fname_buffer), "/data"); errors += add_directory(alloc, fname_buffer, dirs); } } diff --git a/mysys/my_delete.c b/mysys/my_delete.c index 0faf6079d98..beece473a01 100644 --- a/mysys/my_delete.c +++ b/mysys/my_delete.c @@ -83,7 +83,7 @@ static int my_win_unlink(const char *name) { HANDLE handle= INVALID_HANDLE_VALUE; DWORD attributes; - DWORD last_error; + uint last_error; char unique_filename[MAX_PATH + 35]; unsigned long long tsc; /* time stamp counter, for unique filename*/ @@ -148,7 +148,7 @@ static int my_win_unlink(const char *name) name, tsc); if (!MoveFile(name, unique_filename)) { - DBUG_PRINT("warning", ("moving %s to unique filename failed, error %u\n", + DBUG_PRINT("warning", ("moving %s to unique filename failed, error %lu\n", name,GetLastError())); } diff --git a/mysys/my_getopt.c b/mysys/my_getopt.c index c9bfe2e1eaa..830b7f42473 100644 --- a/mysys/my_getopt.c +++ b/mysys/my_getopt.c @@ -236,7 +236,7 @@ int handle_options(int *argc, char ***argv, { is_cmdline_arg= 1; - /* save the separator too if skip unkown options */ + /* save the separator too if skip unknown options */ if (my_getopt_skip_unknown) (*argv)[argvpos++]= cur_arg; else @@ -826,7 +826,7 @@ static int setval(const struct my_option *opts, void *value, char *argument, *((ulonglong*)value)= find_set_from_flags(opts->typelib, opts->typelib->count, *(ulonglong *)value, opts->def_value, - argument, strlen(argument), + argument, (uint)strlen(argument), &error, &error_len); if (error) { @@ -969,31 +969,43 @@ my_bool getopt_compare_strings(register const char *s, register const char *t, /* function: eval_num_suffix - Transforms suffix like k/m/g to their real value. + Transforms suffix like k/m/g/t/p/e to their real value. */ -static inline long eval_num_suffix(char *suffix, int *error) +static inline ulonglong eval_num_suffix(char *suffix, int *error) { - long num= 1; - if (*suffix == 'k' || *suffix == 'K') - num*= 1024L; - else if (*suffix == 'm' || *suffix == 'M') - num*= 1024L * 1024L; - else if (*suffix == 'g' || *suffix == 'G') - num*= 1024L * 1024L * 1024L; - else if (*suffix) - { + switch (*suffix) { + case '\0': + return 1ULL; + case 'k': + case 'K': + return 1ULL << 10; + case 'm': + case 'M': + return 1ULL << 20; + case 'g': + case 'G': + return 1ULL << 30; + case 't': + case 'T': + return 1ULL << 40; + case 'p': + case 'P': + return 1ULL << 50; + case 'e': + case 'E': + return 1ULL << 60; + default: *error= 1; - return 0; + return 0ULL; } - return num; } /* function: eval_num_suffix_ll Transforms a number with a suffix to real number. Suffix can - be k|K for kilo, m|M for mega or g|G for giga. + be k|K for kilo, m|M for mega, etc. */ static longlong eval_num_suffix_ll(char *argument, @@ -1026,7 +1038,7 @@ static longlong eval_num_suffix_ll(char *argument, function: eval_num_suffix_ull Transforms a number with a suffix to positive Integer. Suffix can - be k|K for kilo, m|M for mega or g|G for giga. + be k|K for kilo, m|M for mega, etc. */ static ulonglong eval_num_suffix_ull(char *argument, @@ -1609,7 +1621,7 @@ void my_print_variables(const struct my_option *options) for (optp= options; optp->name; optp++) { - length= strlen(optp->name)+1; + length= (uint)strlen(optp->name)+1; if (length > name_space) name_space= length; } diff --git a/mysys/my_init.c b/mysys/my_init.c index 7db0a58d471..9bd1185a3bf 100644 --- a/mysys/my_init.c +++ b/mysys/my_init.c @@ -105,6 +105,10 @@ my_bool my_init(void) if (my_thread_global_init()) return 1; +#if defined(SAFEMALLOC) && !defined(DBUG_OFF) + dbug_sanity= sf_sanity; +#endif + /* $HOME is needed early to parse configuration files located in ~/ */ if ((home_dir= getenv("HOME")) != 0) home_dir= intern_filename(home_dir_buff, home_dir); diff --git a/mysys/my_lib.c b/mysys/my_lib.c index d5f54f00b85..dc6b7cfd292 100644 --- a/mysys/my_lib.c +++ b/mysys/my_lib.c @@ -119,10 +119,6 @@ MY_DIR *my_dir(const char *path, myf MyFlags) DBUG_ENTER("my_dir"); DBUG_PRINT("my",("path: '%s' MyFlags: %lu",path,MyFlags)); -#if !defined(HAVE_READDIR_R) - mysql_mutex_lock(&THR_LOCK_open); -#endif - tmp_file= directory_file_name(tmp_path, path); if (!(dirp= opendir(tmp_path))) @@ -136,7 +132,7 @@ MY_DIR *my_dir(const char *path, myf MyFlags) MYF(MyFlags))) goto error; - init_alloc_root(&dirh->root, NAMES_START_SIZE, NAMES_START_SIZE, + init_alloc_root(&dirh->root, "dir", NAMES_START_SIZE, NAMES_START_SIZE, MYF(MyFlags)); dp= (struct dirent*) dirent_tmp; @@ -174,9 +170,6 @@ MY_DIR *my_dir(const char *path, myf MyFlags) } (void) closedir(dirp); -#if !defined(HAVE_READDIR_R) - mysql_mutex_unlock(&THR_LOCK_open); -#endif if (MyFlags & MY_WANT_SORT) sort_dynamic(&dirh->array, (qsort_cmp) comp_names); @@ -187,9 +180,6 @@ MY_DIR *my_dir(const char *path, myf MyFlags) DBUG_RETURN(&dirh->dir); error: -#if !defined(HAVE_READDIR_R) - mysql_mutex_unlock(&THR_LOCK_open); -#endif my_errno=errno; if (dirp) (void) closedir(dirp); @@ -216,12 +206,12 @@ MY_DIR *my_dir(const char *path, myf MyFlags) ushort mode; char tmp_path[FN_REFLEN], *tmp_file,attrib; #ifdef _WIN64 - __int64 handle; + __int64 handle= -1; #else - long handle; + long handle= -1; #endif DBUG_ENTER("my_dir"); - DBUG_PRINT("my",("path: '%s' MyFlags: %d",path,MyFlags)); + DBUG_PRINT("my",("path: '%s' MyFlags: %d",path,(int)MyFlags)); /* Put LIB-CHAR as last path-character if not there */ tmp_file=tmp_path; @@ -245,7 +235,7 @@ MY_DIR *my_dir(const char *path, myf MyFlags) MYF(MyFlags))) goto error; - init_alloc_root(&dirh->root, NAMES_START_SIZE, NAMES_START_SIZE, + init_alloc_root(&dirh->root, "dir", NAMES_START_SIZE, NAMES_START_SIZE, MYF(MyFlags)); if ((handle=_findfirst(tmp_path,&find)) == -1L) diff --git a/mysys/my_lock.c b/mysys/my_lock.c index 082d8e9f5a0..34b1723e13c 100644 --- a/mysys/my_lock.c +++ b/mysys/my_lock.c @@ -34,7 +34,6 @@ static int win_lock(File fd, int locktype, my_off_t start, my_off_t length, DWORD dwFlags; OVERLAPPED ov= {0}; HANDLE hFile= (HANDLE)my_get_osfhandle(fd); - DWORD lastError= 0; int i; int timeout_millis= timeout_sec * 1000; diff --git a/mysys/my_malloc.c b/mysys/my_malloc.c index dc02d3896bd..6a3ec8da093 100644 --- a/mysys/my_malloc.c +++ b/mysys/my_malloc.c @@ -109,7 +109,7 @@ void *my_malloc(size_t size, myf my_flags) my_error(EE_OUTOFMEMORY, MYF(ME_BELL + ME_WAITTANG + ME_NOREFRESH + ME_FATALERROR),size); if (my_flags & MY_FAE) - exit(1); + abort(); } else { @@ -200,8 +200,6 @@ void *my_realloc(void *oldpoint, size_t size, myf my_flags) /** Free memory allocated with my_malloc. - @remark Relies on free being able to handle a NULL argument. - @param ptr Pointer to the memory allocated by my_malloc. */ void my_free(void *ptr) @@ -214,6 +212,13 @@ void my_free(void *ptr) my_bool old_flags; old_size= MALLOC_SIZE_AND_FLAG(ptr, &old_flags); update_malloc_size(- (longlong) old_size - MALLOC_PREFIX_SIZE, old_flags); +#ifndef SAFEMALLOC + /* + Trash memory if not safemalloc. We don't have to do this if safemalloc + is used as safemalloc will also do trashing + */ + TRASH_FREE(ptr, old_size); +#endif sf_free(MALLOC_FIX_POINTER_FOR_FREE(ptr)); } DBUG_VOID_RETURN; diff --git a/mysys/my_pthread.c b/mysys/my_pthread.c index 20e53a23ab5..0b84ed0cd82 100644 --- a/mysys/my_pthread.c +++ b/mysys/my_pthread.c @@ -21,6 +21,7 @@ #include <signal.h> #include <m_string.h> #include <thr_alarm.h> +#include <my_pthread.h> #if (defined(__BSD__) || defined(_BSDI_VERSION)) #define SCHED_POLICY SCHED_RR diff --git a/mysys/my_read.c b/mysys/my_read.c index 922da5a7e95..89b368e9800 100644 --- a/mysys/my_read.c +++ b/mysys/my_read.c @@ -35,11 +35,10 @@ size_t my_read(File Filedes, uchar *Buffer, size_t Count, myf MyFlags) { - size_t readbytes, save_count; + size_t readbytes, save_count= 0; DBUG_ENTER("my_read"); DBUG_PRINT("my",("fd: %d Buffer: %p Count: %lu MyFlags: %lu", Filedes, Buffer, (ulong) Count, MyFlags)); - save_count= Count; if (!(MyFlags & (MY_WME | MY_FAE | MY_FNABP))) MyFlags|= my_global_flags; @@ -61,47 +60,52 @@ size_t my_read(File Filedes, uchar *Buffer, size_t Count, myf MyFlags) if (readbytes != Count) { - my_errno= errno; - if (errno == 0 || (readbytes != (size_t) -1 && - (MyFlags & (MY_NABP | MY_FNABP)))) - my_errno= HA_ERR_FILE_TOO_SHORT; + int got_errno= my_errno= errno; DBUG_PRINT("warning",("Read only %d bytes off %lu from %d, errno: %d", (int) readbytes, (ulong) Count, Filedes, - my_errno)); + got_errno)); + + if (got_errno == 0 || (readbytes != (size_t) -1 && + (MyFlags & (MY_NABP | MY_FNABP)))) + my_errno= HA_ERR_FILE_TOO_SHORT; - if ((readbytes == 0 || (int) readbytes == -1) && errno == EINTR) + if ((readbytes == 0 || (int) readbytes == -1) && got_errno == EINTR) { DBUG_PRINT("debug", ("my_read() was interrupted and returned %ld", (long) readbytes)); continue; /* Interrupted */ } + /* Do a read retry if we didn't get enough data on first read */ + if (readbytes != (size_t) -1 && readbytes != 0 && + (MyFlags & MY_FULL_IO)) + { + Buffer+= readbytes; + Count-= readbytes; + save_count+= readbytes; + continue; + } + if (MyFlags & (MY_WME | MY_FAE | MY_FNABP)) { if (readbytes == (size_t) -1) my_error(EE_READ, MYF(ME_BELL | ME_WAITTANG | (MyFlags & (ME_JUST_INFO | ME_NOREFRESH))), - my_filename(Filedes),my_errno); + my_filename(Filedes), got_errno); else if (MyFlags & (MY_NABP | MY_FNABP)) my_error(EE_EOFERR, MYF(ME_BELL | ME_WAITTANG | (MyFlags & (ME_JUST_INFO | ME_NOREFRESH))), - my_filename(Filedes),my_errno); + my_filename(Filedes), got_errno); } if (readbytes == (size_t) -1 || ((MyFlags & (MY_FNABP | MY_NABP)) && !(MyFlags & MY_FULL_IO))) DBUG_RETURN(MY_FILE_ERROR); /* Return with error */ - if (readbytes != (size_t) -1 && (MyFlags & MY_FULL_IO)) - { - Buffer+= readbytes; - Count-= readbytes; - continue; - } } if (MyFlags & (MY_NABP | MY_FNABP)) readbytes= 0; /* Ok on read */ - else if (MyFlags & MY_FULL_IO) - readbytes= save_count; + else + readbytes+= save_count; break; } DBUG_RETURN(readbytes); diff --git a/mysys/my_sync.c b/mysys/my_sync.c index d1e239692f1..cf8dfb6a8c8 100644 --- a/mysys/my_sync.c +++ b/mysys/my_sync.c @@ -133,8 +133,6 @@ int my_sync(File fd, myf my_flags) } /* my_sync */ -static const char cur_dir_name[]= {FN_CURLIB, 0}; - /* Force directory information to disk. @@ -151,6 +149,7 @@ int my_sync_dir(const char *dir_name __attribute__((unused)), myf my_flags __attribute__((unused))) { #ifdef NEED_EXPLICIT_SYNC_DIR + static const char cur_dir_name[]= {FN_CURLIB, 0}; File dir_fd; int res= 0; const char *correct_dir_name; diff --git a/mysys/my_thr_init.c b/mysys/my_thr_init.c index 678bfc459c7..2faa704b998 100644 --- a/mysys/my_thr_init.c +++ b/mysys/my_thr_init.c @@ -341,14 +341,12 @@ void my_thread_end(void) tmp, pthread_self(), tmp ? (long) tmp->id : 0L); #endif -#ifdef HAVE_PSI_INTERFACE /* Remove the instrumentation for this thread. This must be done before trashing st_my_thread_var, because the LF_HASH depends on it. */ - PSI_THREAD_CALL(delete_current_thread)(); -#endif + PSI_CALL_delete_current_thread(); /* We need to disable DBUG early for this thread to ensure that the @@ -385,7 +383,6 @@ void my_thread_end(void) /* Trash variable so that we can detect false accesses to my_thread_var */ tmp->init= 2; - TRASH(tmp, sizeof(*tmp)); free(tmp); } } diff --git a/mysys/my_wincond.c b/mysys/my_wincond.c index 54b272d7025..514e9a92ecf 100644 --- a/mysys/my_wincond.c +++ b/mysys/my_wincond.c @@ -98,9 +98,10 @@ int pthread_attr_init(pthread_attr_t *connect_att) return 0; } -int pthread_attr_setstacksize(pthread_attr_t *connect_att,DWORD stack) +int pthread_attr_setstacksize(pthread_attr_t *connect_att,size_t stack) { - connect_att->dwStackSize=stack; + DBUG_ASSERT(stack < UINT_MAX); + connect_att->dwStackSize=(DWORD)stack; return 0; } diff --git a/mysys/my_windac.c b/mysys/my_windac.c index 9b489759625..720bf3b4894 100644 --- a/mysys/my_windac.c +++ b/mysys/my_windac.c @@ -17,21 +17,6 @@ #include "m_string.h" #ifdef __WIN__ -/* Windows NT/2000 discretionary access control utility functions. */ - -/* - Check if the operating system is built on NT technology. - - RETURN - 0 Windows 95/98/Me - 1 otherwise -*/ - -static my_bool is_nt() -{ - return GetVersion() < 0x80000000; -} - /* Auxiliary structure to store pointers to the data which we need to keep around while SECURITY_ATTRIBUTES is in use. @@ -86,12 +71,6 @@ int my_security_attr_create(SECURITY_ATTRIBUTES **psa, const char **perror, PSID owner_sid; My_security_attr *attr; - if (! is_nt()) - { - *psa= 0; - return 0; - } - /* Get SID of Everyone group. Easier to retrieve all SIDs each time this function is called than worry about thread safety. diff --git a/mysys/my_winerr.c b/mysys/my_winerr.c index a3f6229b74e..ccd94d92d80 100644 --- a/mysys/my_winerr.c +++ b/mysys/my_winerr.c @@ -96,7 +96,7 @@ access violations */ static int get_errno_from_oserr(unsigned long oserrno) { - int i; + size_t i; /* check the table for the OS error code */ for (i= 0; i < ERRTABLESIZE; ++i) diff --git a/mysys/my_winthread.c b/mysys/my_winthread.c index f3335621c38..080eeb49f63 100644 --- a/mysys/my_winthread.c +++ b/mysys/my_winthread.c @@ -79,10 +79,10 @@ int pthread_create(pthread_t *thread_id, const pthread_attr_t *attr, par->arg= param; stack_size= attr?attr->dwStackSize:0; - handle= _beginthreadex(NULL, stack_size , pthread_start, par, 0, thread_id); + handle= _beginthreadex(NULL, stack_size , pthread_start, par, 0, (uint *)thread_id); if (!handle) goto error_return; - DBUG_PRINT("info", ("thread id=%u",*thread_id)); + DBUG_PRINT("info", ("thread id=%lu",*thread_id)); /* Do not need thread handle, close it */ CloseHandle((HANDLE)handle); diff --git a/mysys/mysys_priv.h b/mysys/mysys_priv.h index 892e09148ef..38a75120303 100644 --- a/mysys/mysys_priv.h +++ b/mysys/mysys_priv.h @@ -146,8 +146,12 @@ const char *my_open_parent_dir_nosymlinks(const char *pathname, int *pdfd); return NOAT; #endif +#ifndef _WIN32 #define CREATE_NOSYMLINK_FUNCTION(PROTO,AT,NOAT) \ static int PROTO { NOSYMLINK_FUNCTION_BODY(AT,NOAT) } +#else +#define CREATE_NOSYMLINK_FUNCTION(PROTO,AT,NOAT) +#endif #ifdef _WIN32 #include <sys/stat.h> diff --git a/mysys/safemalloc.c b/mysys/safemalloc.c index b8d9442fbc9..ae8993fbf00 100644 --- a/mysys/safemalloc.c +++ b/mysys/safemalloc.c @@ -330,7 +330,7 @@ static int bad_ptr(const char *where, void *ptr) magicend[3] != MAGICEND3) { DBUG_PRINT("error",("Overrun buffer %p", ptr)); - warn("Error: %s overrun buffer %p", where); + warn("Error: %s overrun buffer %p", where, ptr); fprintf(stderr, "Allocated at "); print_stack(irem->frame); return 1; @@ -340,7 +340,7 @@ static int bad_ptr(const char *where, void *ptr) } /* check all allocated memory list for consistency */ -static int sf_sanity() +int sf_sanity() { struct st_irem *irem; int flag= 0; diff --git a/mysys/stacktrace.c b/mysys/stacktrace.c index 398ade7ad59..619172a5a6a 100644 --- a/mysys/stacktrace.c +++ b/mysys/stacktrace.c @@ -70,7 +70,7 @@ static void print_buffer(char *buffer, size_t count) @return Zero on success. */ -static int safe_print_str(const char *addr, int max_len) +static int safe_print_str(const char *addr, size_t max_len) { int fd; pid_t tid; @@ -147,7 +147,7 @@ static int safe_print_str(const char *addr, int max_len) returns 1, it does not mean 100% that the pointer is corrupted. */ -int my_safe_print_str(const char* val, int max_len) +int my_safe_print_str(const char* val, size_t max_len) { char *heap_end; @@ -703,7 +703,7 @@ void my_print_stacktrace(uchar* unused1, ulong unused2, my_bool silent) if(have_source) { const char *base_file_name= my_basename(line.FileName); - my_safe_printf_stderr("[%s:%u]", + my_safe_printf_stderr("[%s:%lu]", base_file_name, line.LineNumber); } my_safe_printf_stderr("%s", "\n"); @@ -733,7 +733,7 @@ void my_write_core(int unused) if(GetModuleFileName(NULL, path, sizeof(path))) { _splitpath(path, NULL, NULL,dump_fname,NULL); - strncat(dump_fname, ".dmp", sizeof(dump_fname)); + strcat_s(dump_fname, sizeof(dump_fname), ".dmp"); } hFile= CreateFile(dump_fname, GENERIC_WRITE, 0, 0, CREATE_ALWAYS, @@ -763,7 +763,7 @@ void my_write_core(int unused) } -int my_safe_print_str(const char *val, int len) +int my_safe_print_str(const char *val, size_t len) { __try { @@ -780,7 +780,7 @@ int my_safe_print_str(const char *val, int len) size_t my_write_stderr(const void *buf, size_t count) { - return (size_t) write(fileno(stderr), buf, count); + return (size_t) write(fileno(stderr), buf, (uint)count); } diff --git a/mysys/string.c b/mysys/string.c index a0fa3a02e17..18c5f4ec9af 100644 --- a/mysys/string.c +++ b/mysys/string.c @@ -178,9 +178,9 @@ my_bool dynstr_append_quoted(DYNAMIC_STRING *str, const char *append, size_t len, char quote) { - uint additional= (str->alloc_increment ? str->alloc_increment : 10); - uint lim= additional; - uint i; + size_t additional= (str->alloc_increment ? str->alloc_increment : 10); + size_t lim= additional; + size_t i; if (dynstr_realloc(str, len + additional + 2)) return TRUE; str->str[str->length++]= quote; diff --git a/mysys/thr_alarm.c b/mysys/thr_alarm.c index a101c23be58..357923cf388 100644 --- a/mysys/thr_alarm.c +++ b/mysys/thr_alarm.c @@ -36,13 +36,6 @@ #define ETIME ETIMEDOUT #endif -uint thr_client_alarm; -static int alarm_aborted=1; /* No alarm thread */ -my_bool thr_alarm_inited= 0, my_disable_thr_alarm= 0; -volatile my_bool alarm_thread_running= 0; -time_t next_alarm_expire_time= ~ (time_t) 0; -static sig_handler process_alarm_part2(int sig); - #ifdef DBUG_OFF #define reset_index_in_queue(alarm_data) #else @@ -55,9 +48,16 @@ static sig_handler process_alarm_part2(int sig); #define one_signal_hand_sigmask(A,B,C) #endif +my_bool thr_alarm_inited= 0, my_disable_thr_alarm= 0; #if !defined(__WIN__) +uint thr_client_alarm; +static int alarm_aborted=1; /* No alarm thread */ +volatile my_bool alarm_thread_running= 0; +time_t next_alarm_expire_time= ~ (time_t) 0; +static sig_handler process_alarm_part2(int sig); + static mysql_mutex_t LOCK_alarm; static mysql_cond_t COND_alarm; static sigset_t full_signal_set; @@ -274,7 +274,7 @@ void thr_end_alarm(thr_alarm_t *alarmed) /* Come here when some alarm in queue is due. Mark all alarms with are finnished in list. - Shedule alarms to be sent again after 1-10 sec (many alarms at once) + Schedule alarms to be sent again after 1-10 sec (many alarms at once) If alarm_aborted is set then all alarms are given and resent every second. */ @@ -426,7 +426,7 @@ void end_thr_alarm(my_bool free_structures) if (alarm_aborted != 1) /* If memory not freed */ { mysql_mutex_lock(&LOCK_alarm); - DBUG_PRINT("info",("Resheduling %d waiting alarms",alarm_queue.elements)); + DBUG_PRINT("info",("Rescheduling %d waiting alarms",alarm_queue.elements)); alarm_aborted= -1; /* mark aborted */ if (alarm_queue.elements || (alarm_thread_running && free_structures)) { diff --git a/mysys/thr_mutex.c b/mysys/thr_mutex.c index 49cb3ea600f..268a2b80f63 100644 --- a/mysys/thr_mutex.c +++ b/mysys/thr_mutex.c @@ -240,7 +240,7 @@ int safe_mutex_lock(safe_mutex_t *mp, myf my_flags, const char *file, if (!mp->file) { fprintf(stderr, - "safe_mutex: Trying to lock unitialized mutex at %s, line %d\n", + "safe_mutex: Trying to lock uninitialized mutex at %s, line %d\n", file, line); fflush(stderr); abort(); @@ -585,7 +585,7 @@ int safe_mutex_destroy(safe_mutex_t *mp, const char *file, uint line) if (!mp->file) { fprintf(stderr, - "safe_mutex: Trying to destroy unitialized mutex at %s, line %d\n", + "safe_mutex: Trying to destroy uninitialized mutex at %s, line %d\n", file, line); fflush(stderr); abort(); diff --git a/mysys/tree.c b/mysys/tree.c index 13f9bd808a2..b07d56ec942 100644 --- a/mysys/tree.c +++ b/mysys/tree.c @@ -130,7 +130,8 @@ void init_tree(TREE *tree, size_t default_alloc_size, size_t memory_limit, } if (!(tree->with_delete= MY_TEST(my_flags & MY_TREE_WITH_DELETE))) { - init_alloc_root(&tree->mem_root, default_alloc_size, 0, MYF(my_flags)); + init_alloc_root(&tree->mem_root, "tree", default_alloc_size, 0, + MYF(my_flags)); tree->mem_root.min_malloc= sizeof(TREE_ELEMENT)+tree->size_of_element; } DBUG_VOID_RETURN; diff --git a/mysys/typelib.c b/mysys/typelib.c index e45ede2c43a..f0be211fd46 100644 --- a/mysys/typelib.c +++ b/mysys/typelib.c @@ -45,18 +45,6 @@ int find_type_with_warning(const char *x, TYPELIB *typelib, const char *option) } -int find_type_or_exit(const char *x, TYPELIB *typelib, const char *option) -{ - int res; - if ((res= find_type_with_warning(x, typelib, option)) <= 0) - { - sf_leaking_memory= 1; /* no memory leak reports here */ - exit(1); - } - return res; -} - - /** Search after a string in a list of strings. Endspace in x is not compared. diff --git a/mysys/waiting_threads.c b/mysys/waiting_threads.c index df208507590..8e66e0372c1 100644 --- a/mysys/waiting_threads.c +++ b/mysys/waiting_threads.c @@ -618,7 +618,7 @@ retry: { rc= *shared_ptr; lf_pin(arg->thd->pins, 0, rc); - } while (rc != *shared_ptr && LF_BACKOFF); + } while (rc != *shared_ptr && LF_BACKOFF()); if (rc == 0) { |