diff --git a/libmysqld/lib_sql.cc b/libmysqld/lib_sql.cc
index 2d451d6cecdafda8f80ce7f53ca05362fa51432a..741916064b0cfaf333f7c313dd63708fb85fdfc6 100644
--- a/libmysqld/lib_sql.cc
+++ b/libmysqld/lib_sql.cc
@@ -484,7 +484,7 @@ int check_embedded_connection(MYSQL *mysql)
   THD *thd= (THD*)mysql->thd;
   thd->host= (char*)my_localhost;
   thd->host_or_ip= thd->host;
-  thd->user= mysql->user;
+  thd->user= my_strdup(mysql->user, MYF(0));
   return 0;
 }
 
@@ -498,8 +498,8 @@ int check_embedded_connection(MYSQL *mysql)
 
   if (mysql->options.client_ip)
   {
-    thd->host= mysql->options.client_ip;
-    thd->ip= thd->host;
+    thd->host= my_strdup(mysql->options.client_ip, MYF(0));
+    thd->ip= my_strdup(thd->host, MYF(0));
   }
   else
     thd->host= (char*)my_localhost;
@@ -511,7 +511,7 @@ int check_embedded_connection(MYSQL *mysql)
     goto err;
   }
 
-  thd->user= mysql->user;
+  thd->user= my_strdup(mysql->user, MYF(0));
   if (mysql->passwd && mysql->passwd[0])
   {
     memset(thd->scramble, 55, SCRAMBLE_LENGTH); // dummy scramble
diff --git a/sql/sql_class.cc b/sql/sql_class.cc
index ce30c6f3d096f16c85b2079c4a948c06fc85ea3b..7b3d1fd3cd2a568645112e984dd9dfd9b06895d7 100644
--- a/sql/sql_class.cc
+++ b/sql/sql_class.cc
@@ -323,13 +323,11 @@ THD::~THD()
 #endif
 
   DBUG_PRINT("info", ("freeing host"));
-#ifndef EMBEDDED_LIBRARY
   if (host != my_localhost)			// If not pointer to constant
     safeFree(host);
   if (user != delayed_user)
     safeFree(user);
   safeFree(ip);
-#endif
   safeFree(db);
   free_root(&warn_root,MYF(0));
   free_root(&transaction.mem_root,MYF(0));