List:Commits« Previous MessageNext Message »
From:Mats Kindahl Date:November 15 2010 3:17pm
Subject:bzr commit into mysql-5.5-bugteam branch (mats.kindahl:3124) Bug#58173
View as plain text  
#At file:///home/bzr/bugs/b57108-5.5-bugteam/ based on revid:vvaintroub@stripped

 3124 Mats Kindahl	2010-11-15
      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.

    modified:
      mysys/default.c
=== modified file 'mysys/default.c'
--- a/mysys/default.c	2010-11-04 10:00:59 +0000
+++ b/mysys/default.c	2010-11-15 15:17:00 +0000
@@ -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 *pt
  */
 
 static int
-fn_expand(const char *filename, const char **filename_var)
+fn_expand(const char *filename, char result_buf[FN_REFLEN])
 {
-  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 *c
 
   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;


Attachment: [text/bzr-bundle] bzr/mats.kindahl@oracle.com-20101115151700-rv8reekh34i2dt74.bundle
Thread
bzr commit into mysql-5.5-bugteam branch (mats.kindahl:3124) Bug#58173Mats Kindahl15 Nov
Re: bzr commit into mysql-5.5-bugteam branch (mats.kindahl:3124)Bug#58173Alexander Nozdrin16 Nov
  • Re: bzr commit into mysql-5.5-bugteam branch (mats.kindahl:3124)Bug#58173Mats Kindahl16 Nov
Re: bzr commit into mysql-5.5-bugteam branch (mats.kindahl:3124)Bug#58173Dmitry Lenev16 Nov
  • Re: bzr commit into mysql-5.5-bugteam branch (mats.kindahl:3124)Bug#58173Mats Kindahl16 Nov