OSDN Git Service

Fix a memory leak in LogEvent
authorYao Chen <yaochen@google.com>
Sun, 19 Nov 2017 02:56:52 +0000 (18:56 -0800)
committerYao Chen <yaochen@google.com>
Sun, 19 Nov 2017 02:56:52 +0000 (18:56 -0800)
My previous understanding of the liblog api was wrong. Luckily it
is caught in time. Also added a memory profiling tool in another CL.

Test: statsd_test
      adb shell dumpsys meminfo
      adb shell cmd stats meminfo

Change-Id: I742af2a38e52e35edf0d4c77ccc35ede7019a73b

cmds/statsd/src/logd/LogEvent.cpp

index 8023670..1032138 100644 (file)
@@ -30,11 +30,10 @@ using std::string;
 using android::util::ProtoOutputStream;
 
 LogEvent::LogEvent(log_msg& msg) {
-    android_log_context context =
+    mContext =
             create_android_log_parser(msg.msg() + sizeof(uint32_t), msg.len() - sizeof(uint32_t));
     mTimestampNs = msg.entry_v1.sec * NS_PER_SEC + msg.entry_v1.nsec;
-    mContext = NULL;
-    init(context);
+    init(mContext);
 }
 
 LogEvent::LogEvent(int32_t tagId, uint64_t timestampNs) {