Removed malloc while logging.

Change-Id: Ifc5d8f7491a35aa27880af1d0d679c6a81b43b13
diff --git a/aos/common/logging/queue_logging-tmpl.h b/aos/common/logging/queue_logging-tmpl.h
index e0a89e4..b4c3696 100644
--- a/aos/common/logging/queue_logging-tmpl.h
+++ b/aos/common/logging/queue_logging-tmpl.h
@@ -8,11 +8,11 @@
 template <class T>
 void DoLogStruct(log_level level, const ::std::string &message,
                  const T &structure) {
+  auto fn = [&structure](char *buffer)
+                -> size_t { return structure.Serialize(buffer); };
+
   LogImplementation::DoLogStruct(level, message, T::Size(), T::GetType(),
-                                 [&structure](char * buffer)->size_t{
-    return structure.Serialize(buffer);
-  },
-                                 1);
+                                 ::std::ref(fn), 1);
 }
 
 }  // namespace logging
diff --git a/aos/common/logging/queue_logging.cc b/aos/common/logging/queue_logging.cc
index ce96c29..14559fb 100644
--- a/aos/common/logging/queue_logging.cc
+++ b/aos/common/logging/queue_logging.cc
@@ -10,10 +10,13 @@
     log_level level, const ::std::string &message, size_t size,
     const MessageType *type, const ::std::function<size_t(char *)> &serialize,
     int levels) {
-  internal::RunWithCurrentImplementation(
-      levels, [&](LogImplementation * implementation) {
-    implementation->LogStruct(level, message, size, type, serialize);
-  });
+
+  {
+    auto fn = [&](LogImplementation *implementation) {
+      implementation->LogStruct(level, message, size, type, serialize);
+    };
+    internal::RunWithCurrentImplementation(levels, ::std::ref(fn));
+  }
 
   if (level == FATAL) {
     char serialized[1024];