List:Commits« Previous MessageNext Message »
From:Bjorn Munch Date:November 29 2010 3:49pm
Subject:bzr commit into mysql-5.1-mtr branch (bjorn.munch:2956) Bug#58522
View as plain text  
#At file:///home/bm136801/my/lvarset-51/ based on revid:bjorn.munch@stripped

 2956 Bjorn Munch	2010-11-29
      Bug #58522 mtr --debug leaks memory when test fails
      Backported use of setenv() from 5.5
      This will remove the leak on systems that have setenv()
      I have not fixed the string.c leak, it's a local variable
         that the cleanup function cannot access.

    modified:
      client/mysqltest.cc
=== modified file 'client/mysqltest.cc'
--- a/client/mysqltest.cc	2010-11-17 15:05:52 +0000
+++ b/client/mysqltest.cc	2010-11-29 15:44:57 +0000
@@ -73,6 +73,10 @@
 #define QUERY_SEND_FLAG  1
 #define QUERY_REAP_FLAG  2
 
+#ifndef HAVE_SETENV
+static int setenv(const char *name, const char *value, int overwrite);
+#endif
+
 enum {
   OPT_SKIP_SAFEMALLOC=OPT_MAX_CLIENT_OPTION,
   OPT_PS_PROTOCOL, OPT_SP_PROTOCOL, OPT_CURSOR_PROTOCOL, OPT_VIEW_PROTOCOL,
@@ -219,7 +223,6 @@ typedef struct
   int alloced_len;
   int int_dirty; /* do not update string if int is updated until first read */
   int alloced;
-  char *env_s;
 } VAR;
 
 /*Perl/shell-like variable registers */
@@ -1962,7 +1965,7 @@ VAR *var_init(VAR *v, const char *name,
     val_len = strlen(val) ;
   val_alloc_len = val_len + 16; /* room to grow */
   if (!(tmp_var=v) && !(tmp_var = (VAR*)my_malloc(sizeof(*tmp_var)
-                                                  + name_len+1, MYF(MY_WME))))
+                                                  + name_len+2, MYF(MY_WME))))
     die("Out of memory");
 
   tmp_var->name = (name) ? (char*) tmp_var + sizeof(*tmp_var) : 0;
@@ -1971,7 +1974,12 @@ VAR *var_init(VAR *v, const char *name,
   if (!(tmp_var->str_val = (char*)my_malloc(val_alloc_len+1, MYF(MY_WME))))
     die("Out of memory");
 
-  memcpy(tmp_var->name, name, name_len);
+  if (name)
+  {
+    memcpy(tmp_var->name, name, name_len);
+    tmp_var->name[name_len]= 0;
+  }
+  
   if (val)
   {
     memcpy(tmp_var->str_val, val, val_len);
@@ -1982,7 +1990,6 @@ VAR *var_init(VAR *v, const char *name,
   tmp_var->alloced_len = val_alloc_len;
   tmp_var->int_val = (val) ? atoi(val) : 0;
   tmp_var->int_dirty = 0;
-  tmp_var->env_s = 0;
   return tmp_var;
 }
 
@@ -2110,20 +2117,15 @@ void var_set(const char *var_name, const
 
   if (env_var)
   {
-    char buf[1024], *old_env_s= v->env_s;
     if (v->int_dirty)
     {
       sprintf(v->str_val, "%d", v->int_val);
       v->int_dirty= 0;
       v->str_val_len= strlen(v->str_val);
     }
-    my_snprintf(buf, sizeof(buf), "%.*s=%.*s",
-                v->name_len, v->name,
-                v->str_val_len, v->str_val);
-    if (!(v->env_s= my_strdup(buf, MYF(MY_WME))))
-      die("Out of memory");
-    putenv(v->env_s);
-    my_free(old_env_s, MYF(MY_ALLOW_ZERO_PTR));
+    /* setenv() expects \0-terminated strings */
+    DBUG_ASSERT(v->name[v->name_len] == 0);
+    setenv(v->name, v->str_val, 1);
   }
   DBUG_VOID_RETURN;
 }
@@ -9899,3 +9901,18 @@ void dynstr_append_sorted(DYNAMIC_STRING
   delete_dynamic(&lines);
   DBUG_VOID_RETURN;
 }
+
+#ifndef HAVE_SETENV
+static int setenv(const char *name, const char *value, int overwrite)
+{
+ size_t buflen= strlen(name) + strlen(value) + 2;
+ char *envvar= (char *)malloc(buflen);
+ if(!envvar)
+ return ENOMEM;
+ strcpy(envvar, name);
+ strcat(envvar, "=");
+ strcat(envvar, value);
+ putenv(envvar);
+ return 0;
+}
+#endif


Attachment: [text/bzr-bundle] bzr/bjorn.munch@oracle.com-20101129154457-edwkg1ijv5xp4skp.bundle
Thread
bzr commit into mysql-5.1-mtr branch (bjorn.munch:2956) Bug#58522Bjorn Munch29 Nov