OSDN Git Service

Fix a memory leak in the osi allocation tracker
authorPavlin Radoslavov <pavlin@google.com>
Fri, 3 Feb 2017 03:47:16 +0000 (19:47 -0800)
committerPavlin Radoslavov <pavlin@google.com>
Fri, 3 Feb 2017 03:47:16 +0000 (19:47 -0800)
Add a missing free(allocation) inside allocation_tracker_notify_free()
when freeing a memory buffer.

Prior to switching the allocation tracker to use C++ unordered_map,
the "allocation" bin was kept within (and reused) by the older hash_map
mechanism. However, after the switch to the C++ unordered_map this
is no longer the case, hence the memory leak.

Test: watch -n 1 "adb shell dumpsys meminfo -d BT-PID | grep Heap"
Bug: 34785845
Change-Id: I737c901a6452d29d18fd8b847e7d5ea10c5ff485

osi/src/allocation_tracker.cc

index 461e342..2dee1dc 100644 (file)
@@ -165,6 +165,7 @@ void* allocation_tracker_notify_free(UNUSED_ATTR uint8_t allocator_id,
   // Double-free of memory is detected with "assert(allocation)" above
   // as the allocation entry will not be present.
   allocations.erase(ptr);
+  free(allocation);
 
   return ((char*)ptr) - canary_size;
 }