summaryrefslogtreecommitdiff
path: root/mysys
diff options
context:
space:
mode:
authorMats Kindahl <mats.kindahl@oracle.com>2010-11-16 11:58:39 +0100
committerMats Kindahl <mats.kindahl@oracle.com>2010-11-16 11:58:39 +0100
commit34b8e774b8b16ccc865d7211276599a8b1532ec6 (patch)
treee9b038766cdefb61f9b543cb27c0bdb6b53fa7fa /mysys
parent9893c5a248c6fcbe33b4bed76979409eda2ebf52 (diff)
downloadmariadb-git-34b8e774b8b16ccc865d7211276599a8b1532ec6.tar.gz
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.
Diffstat (limited to 'mysys')
-rw-r--r--mysys/default.c24
1 files changed, 13 insertions, 11 deletions
diff --git a/mysys/default.c b/mysys/default.c
index a57f1150816..75eb4709e1e 100644
--- a/mysys/default.c
+++ b/mysys/default.c
@@ -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;