mirror of
https://github.com/MariaDB/server.git
synced 2025-01-19 13:32:33 +01:00
Bug #58173: Valgrind warning in load_defaults()
Memory was allocated for storing path names inside fn_expand(), which were not free:ed anywhere. This patch fixes the problem by storing the path names in statically allocated buffers instead, which is automatically free:ed when the server exits.
This commit is contained in:
parent
616f90b372
commit
3219886dc2
1 changed files with 13 additions and 11 deletions
|
@ -68,6 +68,9 @@ const char *my_defaults_file=0;
|
|||
const char *my_defaults_group_suffix=0;
|
||||
const char *my_defaults_extra_file=0;
|
||||
|
||||
static char my_defaults_file_buffer[FN_REFLEN];
|
||||
static char my_defaults_extra_file_buffer[FN_REFLEN];
|
||||
|
||||
static my_bool defaults_already_read= FALSE;
|
||||
|
||||
/* Which directories are searched for options (and in which order) */
|
||||
|
@ -152,22 +155,19 @@ static char *remove_end_comment(char *ptr);
|
|||
*/
|
||||
|
||||
static int
|
||||
fn_expand(const char *filename, const char **filename_var)
|
||||
fn_expand(const char *filename, char *result_buf)
|
||||
{
|
||||
char dir[FN_REFLEN], buf[FN_REFLEN];
|
||||
char dir[FN_REFLEN];
|
||||
const int flags= MY_UNPACK_FILENAME | MY_SAFE_PATH | MY_RELATIVE_PATH;
|
||||
const char *result_path= NULL;
|
||||
DBUG_ENTER("fn_expand");
|
||||
DBUG_PRINT("enter", ("filename: %s, buf: 0x%lx", filename, (unsigned long) buf));
|
||||
DBUG_PRINT("enter", ("filename: %s, result_buf: 0x%lx",
|
||||
filename, (unsigned long) result_buf));
|
||||
if (my_getwd(dir, sizeof(dir), MYF(0)))
|
||||
DBUG_RETURN(3);
|
||||
DBUG_PRINT("debug", ("dir: %s", dir));
|
||||
if (fn_format(buf, filename, dir, NULL, flags) == NULL ||
|
||||
(result_path= my_strdup(buf, MYF(0))) == NULL)
|
||||
if (fn_format(result_buf, filename, dir, NULL, flags) == NULL)
|
||||
DBUG_RETURN(2);
|
||||
DBUG_PRINT("return", ("result: %s", result_path));
|
||||
DBUG_ASSERT(result_path != NULL);
|
||||
*filename_var= result_path;
|
||||
DBUG_PRINT("return", ("result: %s", result_buf));
|
||||
DBUG_RETURN(0);
|
||||
}
|
||||
|
||||
|
@ -224,16 +224,18 @@ int my_search_option_files(const char *conf_file, int *argc, char ***argv,
|
|||
|
||||
if (forced_extra_defaults && !defaults_already_read)
|
||||
{
|
||||
int error= fn_expand(forced_extra_defaults, &my_defaults_extra_file);
|
||||
int error= fn_expand(forced_extra_defaults, my_defaults_extra_file_buffer);
|
||||
if (error)
|
||||
DBUG_RETURN(error);
|
||||
my_defaults_extra_file= my_defaults_extra_file_buffer;
|
||||
}
|
||||
|
||||
if (forced_default_file && !defaults_already_read)
|
||||
{
|
||||
int error= fn_expand(forced_default_file, &my_defaults_file);
|
||||
int error= fn_expand(forced_default_file, my_defaults_file_buffer);
|
||||
if (error)
|
||||
DBUG_RETURN(error);
|
||||
my_defaults_file= my_defaults_file_buffer;
|
||||
}
|
||||
|
||||
defaults_already_read= TRUE;
|
||||
|
|
Loading…
Reference in a new issue