Fixed a memory leak from the thread name.

Change-Id: I291c16b54b48bddf9240c8aecc7261030fae3466
diff --git a/aos/common/logging/logging_impl.cc b/aos/common/logging/logging_impl.cc
index 724d4b8..c776991 100644
--- a/aos/common/logging/logging_impl.cc
+++ b/aos/common/logging/logging_impl.cc
@@ -80,8 +80,8 @@
 
   message->level = level;
   message->source = context->source;
-  memcpy(message->name, context->name.c_str(), context->name.size());
-  message->name_length = context->name.size();
+  memcpy(message->name, context->name, context->name_size);
+  message->name_length = context->name_size;
 
   time::Time now = time::Time::Now();
   message->seconds = now.sec();
diff --git a/aos/common/logging/logging_impl.h b/aos/common/logging/logging_impl.h
index 35e24a0..367c1a1 100644
--- a/aos/common/logging/logging_impl.h
+++ b/aos/common/logging/logging_impl.h
@@ -281,8 +281,8 @@
   LogImplementation *implementation;
 
   // A name representing this task/(process and thread).
-  // strlen(name.c_str()) must be <= sizeof(LogMessage::name).
-  ::std::string name;
+  char name[sizeof(LogMessage::name)];
+  size_t name_size;
 
   // What to assign LogMessage::source to in this task/thread.
   pid_t source;
diff --git a/aos/common/logging/logging_impl_test.cc b/aos/common/logging/logging_impl_test.cc
index 8331c37..d426112 100644
--- a/aos/common/logging/logging_impl_test.cc
+++ b/aos/common/logging/logging_impl_test.cc
@@ -63,13 +63,13 @@
           static_cast<uint32_t>(log_implementation->message().source),
           static_cast<uint32_t>(context->source));
     }
-    if (log_implementation->message().name_length != context->name.size() ||
-        memcmp(log_implementation->message().name, context->name.c_str(),
-               context->name.size()) !=
+    if (log_implementation->message().name_length != context->name_size ||
+        memcmp(log_implementation->message().name, context->name,
+               context->name_size) !=
             0) {
       LOG(FATAL, "got a message from %.*s, but we're %s\n",
           static_cast<int>(log_implementation->message().name_length),
-          log_implementation->message().name, context->name.c_str());
+          log_implementation->message().name, context->name);
     }
     if (strstr(log_implementation->message().message, message.c_str())
         == NULL) {
diff --git a/aos/linux_code/logging/linux_interface.cc b/aos/linux_code/logging/linux_interface.cc
index 4e8317b..626b2ee 100644
--- a/aos/linux_code/logging/linux_interface.cc
+++ b/aos/linux_code/logging/linux_interface.cc
@@ -54,11 +54,13 @@
 // Used in aos/linux_code/init.cc when a thread's name is changed.
 void ReloadThreadName() {
   if (my_context.created()) {
-    my_context->name = GetMyName();
-    if (my_context->name.size() + 1 > sizeof(LogMessage::name)) {
+    ::std::string my_name = GetMyName();
+    if (my_name.size() + 1 > sizeof(Context::name)) {
       Die("logging: process/thread name '%s' is too long\n",
-          my_context->name.c_str());
+          my_name.c_str());
     }
+    strcpy(my_context->name, my_name.c_str());
+    my_context->name_size = my_name.size();
   }
 }
 
@@ -69,7 +71,6 @@
   }
   if (__builtin_expect(!my_context.created(), false)) {
     my_context.Create();
-    my_context->name = GetMyName();
     ReloadThreadName();
     my_context->source = getpid();
   }