diff options
author | unknown <acurtis/antony@xiphis.org/ltamd64.xiphis.org> | 2007-10-04 10:55:08 -0700 |
---|---|---|
committer | unknown <acurtis/antony@xiphis.org/ltamd64.xiphis.org> | 2007-10-04 10:55:08 -0700 |
commit | 1c94c8e674735337af6170cc21db3f685fe4e321 (patch) | |
tree | d62a7dda2fcb26f6bd04fe1653abe226e24daa01 /mysys/my_getopt.c | |
parent | c0850719bc7d02985c98b3ecf6c0ec0b0acecacf (diff) | |
download | mariadb-git-1c94c8e674735337af6170cc21db3f685fe4e321.tar.gz |
Bug#31382
"Disabled plugin is provoking Valgrind error"
If there are any auto-alloced string plug-in options, memory is
allocated during the call for handle_options(). We must free this
memory if we are not installing the plug-in.
include/my_getopt.h:
bug31382
new function: my_cleanup_options()
mysys/my_getopt.c:
bug31382
new function: my_cleanup_options(), fini_one_value()
alter init_variables() to take an extra option.
forward declare init_one_value() and fini_one_value()
sql/sql_plugin.cc:
bug31382
after calling handle_options(), make sure to call my_cleanup_options()
if we are not installing the plug-in.
Diffstat (limited to 'mysys/my_getopt.c')
-rw-r--r-- | mysys/my_getopt.c | 46 |
1 files changed, 43 insertions, 3 deletions
diff --git a/mysys/my_getopt.c b/mysys/my_getopt.c index 3a5b130e067..6ed03067d60 100644 --- a/mysys/my_getopt.c +++ b/mysys/my_getopt.c @@ -20,6 +20,9 @@ #include <mysys_err.h> #include <my_getopt.h> +typedef void (*init_func_p)(const struct my_option *option, uchar* *variable, + longlong value); + static void default_reporter(enum loglevel level, const char *format, ...); my_error_reporter my_getopt_error_reporter= &default_reporter; @@ -33,7 +36,12 @@ static longlong getopt_ll(char *arg, const struct my_option *optp, int *err); static ulonglong getopt_ull(char *arg, const struct my_option *optp, int *err); static double getopt_double(char *arg, const struct my_option *optp, int *err); -static void init_variables(const struct my_option *options); +static void init_variables(const struct my_option *options, + init_func_p init_one_value); +static void init_one_value(const struct my_option *option, uchar* *variable, + longlong value); +static void fini_one_value(const struct my_option *option, uchar* *variable, + longlong value); static int setval(const struct my_option *opts, uchar* *value, char *argument, my_bool set_maximum_value); static char *check_struct_option(char *cur_arg, char *key_name); @@ -117,7 +125,7 @@ int handle_options(int *argc, char ***argv, DBUG_ASSERT(argv && *argv); (*argc)--; /* Skip the program name */ (*argv)++; /* --- || ---- */ - init_variables(longopts); + init_variables(longopts, init_one_value); for (pos= *argv, pos_end=pos+ *argc; pos != pos_end ; pos++) { @@ -906,6 +914,37 @@ static void init_one_value(const struct my_option *option, uchar* *variable, } +/* + Init one value to it's default values + + SYNOPSIS + init_one_value() + option Option to initialize + value Pointer to variable +*/ + +static void fini_one_value(const struct my_option *option, uchar* *variable, + longlong value __attribute__ ((unused))) +{ + DBUG_ENTER("fini_one_value"); + switch ((option->var_type & GET_TYPE_MASK)) { + case GET_STR_ALLOC: + my_free((*(char**) variable), MYF(MY_ALLOW_ZERO_PTR)); + *((char**) variable)= NULL; + break; + default: /* dummy default to avoid compiler warnings */ + break; + } + DBUG_VOID_RETURN; +} + + +void my_cleanup_options(const struct my_option *options) +{ + init_variables(options, fini_one_value); +} + + /* initialize all variables to their default values @@ -919,7 +958,8 @@ static void init_one_value(const struct my_option *option, uchar* *variable, for a value and initialize. */ -static void init_variables(const struct my_option *options) +static void init_variables(const struct my_option *options, + init_func_p init_one_value) { DBUG_ENTER("init_variables"); for (; options->name; options++) |