summaryrefslogtreecommitdiff
path: root/mysys
diff options
context:
space:
mode:
Diffstat (limited to 'mysys')
-rw-r--r--mysys/mf_wfile.c2
-rw-r--r--mysys/my_alloc.c18
-rw-r--r--mysys/my_getopt.c39
-rw-r--r--mysys/my_malloc.c12
-rw-r--r--mysys/safemalloc.c12
-rw-r--r--mysys/thr_alarm.c10
6 files changed, 65 insertions, 28 deletions
diff --git a/mysys/mf_wfile.c b/mysys/mf_wfile.c
index f98d348994e..4a4fb466600 100644
--- a/mysys/mf_wfile.c
+++ b/mysys/mf_wfile.c
@@ -119,6 +119,6 @@ void wf_end(WF_PACK *buffer)
{
DBUG_ENTER("wf_end");
if (buffer)
- my_free((uchar*) buffer,MYF(0));
+ my_free(buffer, MYF(0));
DBUG_VOID_RETURN;
} /* wf_end */
diff --git a/mysys/my_alloc.c b/mysys/my_alloc.c
index 8d3bc0c3fb2..948d3a8476d 100644
--- a/mysys/my_alloc.c
+++ b/mysys/my_alloc.c
@@ -153,6 +153,14 @@ void *alloc_root(MEM_ROOT *mem_root, size_t length)
DBUG_ASSERT(alloc_root_inited(mem_root));
+ DBUG_EXECUTE_IF("simulate_out_of_memory",
+ {
+ if (mem_root->error_handler)
+ (*mem_root->error_handler)();
+ DBUG_SET("-d,simulate_out_of_memory");
+ DBUG_RETURN((void*) 0); /* purecov: inspected */
+ });
+
length+=ALIGN_SIZE(sizeof(USED_MEM));
if (!(next = (USED_MEM*) my_malloc(length,MYF(MY_WME))))
{
@@ -175,6 +183,14 @@ void *alloc_root(MEM_ROOT *mem_root, size_t length)
DBUG_PRINT("enter",("root: 0x%lx", (long) mem_root));
DBUG_ASSERT(alloc_root_inited(mem_root));
+ DBUG_EXECUTE_IF("simulate_out_of_memory",
+ {
+ /* Avoid reusing an already allocated block */
+ if (mem_root->error_handler)
+ (*mem_root->error_handler)();
+ DBUG_SET("-d,simulate_out_of_memory");
+ DBUG_RETURN((void*) 0); /* purecov: inspected */
+ });
length= ALIGN_SIZE(length);
if ((*(prev= &mem_root->free)) != NULL)
{
@@ -275,7 +291,7 @@ void *multi_alloc_root(MEM_ROOT *root, ...)
DBUG_RETURN((void*) start);
}
-#define TRASH_MEM(X) VALGRIND_MAKE_MEM_UNDEFINED(((char*)(X) + ((X)->size-(X)->left)), (X)->left)
+#define TRASH_MEM(X) TRASH(((char*)(X) + ((X)->size-(X)->left)), (X)->left)
/* Mark all data in blocks free for reusage */
diff --git a/mysys/my_getopt.c b/mysys/my_getopt.c
index 1c5aa3735ec..82a691d550a 100644
--- a/mysys/my_getopt.c
+++ b/mysys/my_getopt.c
@@ -22,7 +22,7 @@
#include <errno.h>
#include <m_string.h>
-typedef void (*init_func_p)(const struct my_option *option, uchar* *variable,
+typedef void (*init_func_p)(const struct my_option *option, void *variable,
longlong value);
static void default_reporter(enum loglevel level, const char *format, ...);
@@ -40,11 +40,12 @@ static ulonglong getopt_ull(char *arg, const struct my_option *optp,
static double getopt_double(char *arg, const struct my_option *optp, int *err);
static void init_variables(const struct my_option *options,
init_func_p init_one_value);
-static void init_one_value(const struct my_option *opt, uchar* *, longlong);
-static void fini_one_value(const struct my_option *option, uchar* *variable,
+static void init_one_value(const struct my_option *option, void *variable,
longlong value);
-static int setval(const struct my_option *opts, uchar **value, char *argument,
- my_bool set_maximum_value);
+static void fini_one_value(const struct my_option *option, void *variable,
+ longlong value);
+static int setval(const struct my_option *opts, void *value, char *argument,
+ my_bool set_maximum_value);
static char *check_struct_option(char *cur_arg, char *key_name);
/*
@@ -100,10 +101,9 @@ static void default_reporter(enum loglevel level,
one. Call function 'get_one_option()' once for each option.
*/
-static uchar** (*getopt_get_addr)(const char *, uint, const struct my_option *, int *);
+static my_getopt_value getopt_get_addr;
-void my_getopt_register_get_addr(uchar** (*func_addr)(const char *, uint,
- const struct my_option *, int *))
+void my_getopt_register_get_addr(my_getopt_value func_addr)
{
getopt_get_addr= func_addr;
}
@@ -118,7 +118,7 @@ int handle_options(int *argc, char ***argv,
char **pos, **pos_end, *optend, *UNINIT_VAR(prev_found),
*opt_str, key_name[FN_REFLEN];
const struct my_option *optp;
- uchar* *value;
+ void *value;
int error, i;
LINT_INIT(opt_found);
@@ -172,7 +172,7 @@ int handle_options(int *argc, char ***argv,
"%s: Option '--set-variable' is deprecated. "
"Use --variable-name=value instead.",
my_progname);
-
+
must_be_var= 1;
if (cur_arg[13] == '=')
{
@@ -377,7 +377,7 @@ int handle_options(int *argc, char ***argv,
optp->value;
if (error)
return error;
-
+
if (optp->arg_type == NO_ARG)
{
if (optend && (optp->var_type & GET_TYPE_MASK) != GET_BOOL)
@@ -405,8 +405,8 @@ int handle_options(int *argc, char ***argv,
else
{
my_getopt_error_reporter(WARNING_LEVEL,
- "%s: ignoring option '--%s' due to \
-invalid value '%s'",
+ "%s: ignoring option '--%s' due to "
+ "invalid value '%s'",
my_progname, optp->name, optend);
continue;
}
@@ -610,7 +610,7 @@ static char *check_struct_option(char *cur_arg, char *key_name)
Will set the option value to given value
*/
-static int setval(const struct my_option *opts, uchar* *value, char *argument,
+static int setval(const struct my_option *opts, void *value, char *argument,
my_bool set_maximum_value)
{
int err= 0;
@@ -618,8 +618,7 @@ static int setval(const struct my_option *opts, uchar* *value, char *argument,
if (value && argument)
{
- uchar* *result_pos= ((set_maximum_value) ?
- opts->u_max_value : value);
+ void *result_pos= ((set_maximum_value) ? opts->u_max_value : value);
if (!result_pos)
return EXIT_NO_PTR_TO_VARIABLE;
@@ -994,7 +993,7 @@ static double getopt_double(char *arg, const struct my_option *optp, int *err)
value Pointer to variable
*/
-static void init_one_value(const struct my_option *option, uchar* *variable,
+static void init_one_value(const struct my_option *option, void *variable,
longlong value)
{
DBUG_ENTER("init_one_value");
@@ -1068,7 +1067,7 @@ static void init_one_value(const struct my_option *option, uchar* *variable,
value Pointer to variable
*/
-static void fini_one_value(const struct my_option *option, uchar* *variable,
+static void fini_one_value(const struct my_option *option, void *variable,
longlong value __attribute__ ((unused)))
{
DBUG_ENTER("fini_one_value");
@@ -1109,7 +1108,7 @@ static void init_variables(const struct my_option *options,
DBUG_ENTER("init_variables");
for (; options->name; options++)
{
- uchar* *variable;
+ void *variable;
DBUG_PRINT("options", ("name: '%s'", options->name));
/*
We must set u_max_value first as for some variables
@@ -1224,7 +1223,7 @@ void my_print_variables(const struct my_option *options)
printf("--------------------------------- -----------------------------\n");
for (optp= options; optp->id; optp++)
{
- uchar* *value= (optp->var_type & GET_ASK_ADDR ?
+ void *value= (optp->var_type & GET_ASK_ADDR ?
(*getopt_get_addr)("", 0, optp, 0) : optp->value);
if (value)
{
diff --git a/mysys/my_malloc.c b/mysys/my_malloc.c
index 12af5603a93..330ef07ed30 100644
--- a/mysys/my_malloc.c
+++ b/mysys/my_malloc.c
@@ -34,13 +34,23 @@ void *my_malloc(size_t size, myf my_flags)
if (!size)
size=1; /* Safety */
- if ((point = (char*)malloc(size)) == NULL)
+
+ point= (char *) malloc(size);
+ DBUG_EXECUTE_IF("simulate_out_of_memory",
+ {
+ free(point);
+ point= NULL;
+ });
+
+ if (point == NULL)
{
my_errno=errno;
if (my_flags & MY_FAE)
error_handler_hook=fatal_error_handler_hook;
if (my_flags & (MY_FAE+MY_WME))
my_error(EE_OUTOFMEMORY, MYF(ME_BELL+ME_WAITTANG+ME_NOREFRESH),size);
+ DBUG_EXECUTE_IF("simulate_out_of_memory",
+ DBUG_SET("-d,simulate_out_of_memory"););
if (my_flags & MY_FAE)
exit(1);
}
diff --git a/mysys/safemalloc.c b/mysys/safemalloc.c
index d6cd3896b08..0d0ae2dabe5 100644
--- a/mysys/safemalloc.c
+++ b/mysys/safemalloc.c
@@ -139,6 +139,11 @@ void *_mymalloc(size_t size, const char *filename, uint lineno, myf MyFlags)
size + /* size requested */
4 + /* overrun mark */
sf_malloc_endhunc);
+ DBUG_EXECUTE_IF("simulate_out_of_memory",
+ {
+ free(irem);
+ irem= NULL;
+ });
}
/* Check if there isn't anymore memory avaiable */
if (!irem)
@@ -159,6 +164,8 @@ void *_mymalloc(size_t size, const char *filename, uint lineno, myf MyFlags)
}
DBUG_PRINT("error",("Out of memory, in use: %ld at line %d, '%s'",
(ulong) sf_malloc_max_memory,lineno, filename));
+ DBUG_EXECUTE_IF("simulate_out_of_memory",
+ DBUG_SET("-d,simulate_out_of_memory"););
if (MyFlags & MY_FAE)
exit(1);
DBUG_RETURN ((void*) 0);
@@ -190,9 +197,12 @@ void *_mymalloc(size_t size, const char *filename, uint lineno, myf MyFlags)
sf_malloc_count++;
pthread_mutex_unlock(&THR_LOCK_malloc);
+ MEM_CHECK_ADDRESSABLE(data, size);
/* Set the memory to the aribtrary wierd value */
if ((MyFlags & MY_ZEROFILL) || !sf_malloc_quick)
bfill(data, size, (char) (MyFlags & MY_ZEROFILL ? 0 : ALLOC_VAL));
+ if (!(MyFlags & MY_ZEROFILL))
+ MEM_UNDEFINED(data, size);
/* Return a pointer to the real data */
DBUG_PRINT("exit",("ptr: %p", data));
if (sf_min_adress > data)
@@ -312,7 +322,9 @@ void _myfree(void *ptr, const char *filename, uint lineno, myf myflags)
if (!sf_malloc_quick)
bfill(ptr, irem->datasize, (pchar) FREE_VAL);
#endif
+ MEM_NOACCESS(ptr, irem->datasize);
*((uint32*) ((char*) ptr- sizeof(uint32)))= ~MAGICKEY;
+ MEM_NOACCESS((char*) ptr - sizeof(uint32), sizeof(uint32));
/* Actually free the memory */
free((char*) irem);
DBUG_VOID_RETURN;
diff --git a/mysys/thr_alarm.c b/mysys/thr_alarm.c
index b710a7eee39..386691be4de 100644
--- a/mysys/thr_alarm.c
+++ b/mysys/thr_alarm.c
@@ -306,7 +306,7 @@ sig_handler process_alarm(int sig __attribute__((unused)))
#if defined(MAIN) && !defined(__bsdi__)
printf("thread_alarm in process_alarm\n"); fflush(stdout);
#endif
-#ifdef DONT_REMEMBER_SIGNAL
+#ifdef SIGNAL_HANDLER_RESET_ON_DELIVERY
my_sigset(thr_client_alarm, process_alarm); /* int. thread system calls */
#endif
return;
@@ -325,7 +325,7 @@ sig_handler process_alarm(int sig __attribute__((unused)))
#endif
process_alarm_part2(sig);
#ifndef USE_ALARM_THREAD
-#if defined(DONT_REMEMBER_SIGNAL) && !defined(USE_ONE_SIGNAL_HAND)
+#if defined(SIGNAL_HANDLER_RESET_ON_DELIVERY) && !defined(USE_ONE_SIGNAL_HAND)
my_sigset(THR_SERVER_ALARM,process_alarm);
#endif
pthread_mutex_unlock(&LOCK_alarm);
@@ -523,12 +523,12 @@ void thr_alarm_info(ALARM_INFO *info)
*/
-static sig_handler thread_alarm(int sig)
+static sig_handler thread_alarm(int sig __attribute__((unused)))
{
#ifdef MAIN
printf("thread_alarm\n"); fflush(stdout);
#endif
-#ifdef DONT_REMEMBER_SIGNAL
+#ifdef SIGNAL_HANDLER_RESET_ON_DELIVERY
my_sigset(sig,thread_alarm); /* int. thread system calls */
#endif
}
@@ -797,7 +797,7 @@ static sig_handler print_signal_warning(int sig)
{
printf("Warning: Got signal %d from thread %s\n",sig,my_thread_name());
fflush(stdout);
-#ifdef DONT_REMEMBER_SIGNAL
+#ifdef SIGNAL_HANDLER_RESET_ON_DELIVERY
my_sigset(sig,print_signal_warning); /* int. thread system calls */
#endif
if (sig == SIGALRM)