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.
This commit is contained in:
parent
0f36ce8f86
commit
3060f0be8e
@ -68,6 +68,7 @@ extern my_error_reporter my_getopt_error_reporter;
|
|||||||
|
|
||||||
extern int handle_options (int *argc, char ***argv,
|
extern int handle_options (int *argc, char ***argv,
|
||||||
const struct my_option *longopts, my_get_one_option);
|
const struct my_option *longopts, my_get_one_option);
|
||||||
|
extern void my_cleanup_options(const struct my_option *options);
|
||||||
extern void my_print_help(const struct my_option *options);
|
extern void my_print_help(const struct my_option *options);
|
||||||
extern void my_print_variables(const struct my_option *options);
|
extern void my_print_variables(const struct my_option *options);
|
||||||
extern void my_getopt_register_get_addr(uchar ** (*func_addr)(const char *, uint,
|
extern void my_getopt_register_get_addr(uchar ** (*func_addr)(const char *, uint,
|
||||||
|
@ -20,6 +20,9 @@
|
|||||||
#include <mysys_err.h>
|
#include <mysys_err.h>
|
||||||
#include <my_getopt.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, ...);
|
static void default_reporter(enum loglevel level, const char *format, ...);
|
||||||
my_error_reporter my_getopt_error_reporter= &default_reporter;
|
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,
|
static ulonglong getopt_ull(char *arg, const struct my_option *optp,
|
||||||
int *err);
|
int *err);
|
||||||
static double getopt_double(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,
|
static int setval(const struct my_option *opts, uchar* *value, char *argument,
|
||||||
my_bool set_maximum_value);
|
my_bool set_maximum_value);
|
||||||
static char *check_struct_option(char *cur_arg, char *key_name);
|
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);
|
DBUG_ASSERT(argv && *argv);
|
||||||
(*argc)--; /* Skip the program name */
|
(*argc)--; /* Skip the program name */
|
||||||
(*argv)++; /* --- || ---- */
|
(*argv)++; /* --- || ---- */
|
||||||
init_variables(longopts);
|
init_variables(longopts, init_one_value);
|
||||||
|
|
||||||
for (pos= *argv, pos_end=pos+ *argc; pos != pos_end ; pos++)
|
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
|
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.
|
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");
|
DBUG_ENTER("init_variables");
|
||||||
for (; options->name; options++)
|
for (; options->name; options++)
|
||||||
|
@ -3092,7 +3092,7 @@ static int test_plugin_options(MEM_ROOT *tmp_root, struct st_plugin_int *tmp,
|
|||||||
{
|
{
|
||||||
sql_print_error("Parsing options for plugin '%s' failed.",
|
sql_print_error("Parsing options for plugin '%s' failed.",
|
||||||
tmp->name.str);
|
tmp->name.str);
|
||||||
DBUG_RETURN(error);
|
goto err;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -3102,6 +3102,8 @@ static int test_plugin_options(MEM_ROOT *tmp_root, struct st_plugin_int *tmp,
|
|||||||
*enabled= TRUE;
|
*enabled= TRUE;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
error= 1;
|
||||||
|
|
||||||
if (*enabled)
|
if (*enabled)
|
||||||
{
|
{
|
||||||
for (opt= tmp->plugin->system_vars; opt && *opt; opt++)
|
for (opt= tmp->plugin->system_vars; opt && *opt; opt++)
|
||||||
@ -3140,7 +3142,7 @@ static int test_plugin_options(MEM_ROOT *tmp_root, struct st_plugin_int *tmp,
|
|||||||
{
|
{
|
||||||
sql_print_error("Plugin '%s' has conflicting system variables",
|
sql_print_error("Plugin '%s' has conflicting system variables",
|
||||||
tmp->name.str);
|
tmp->name.str);
|
||||||
DBUG_RETURN(1);
|
goto err;
|
||||||
}
|
}
|
||||||
tmp->system_vars= chain.first;
|
tmp->system_vars= chain.first;
|
||||||
}
|
}
|
||||||
@ -3150,7 +3152,9 @@ static int test_plugin_options(MEM_ROOT *tmp_root, struct st_plugin_int *tmp,
|
|||||||
if (enabled_saved && global_system_variables.log_warnings)
|
if (enabled_saved && global_system_variables.log_warnings)
|
||||||
sql_print_information("Plugin '%s' disabled by command line option",
|
sql_print_information("Plugin '%s' disabled by command line option",
|
||||||
tmp->name.str);
|
tmp->name.str);
|
||||||
DBUG_RETURN(1);
|
err:
|
||||||
|
my_cleanup_options(opts);
|
||||||
|
DBUG_RETURN(error);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user