aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFlorian Mayer <fmayer@google.com>2019-07-12 13:31:38 +0100
committerFlorian Mayer <fmayer@google.com>2019-07-17 13:08:31 +0000
commit62b8eb7c6ae9f3ef546c35ff741c7cbbfea106a6 (patch)
tree9c1392794a0908fa504cdb3a8ef015cbcc0a886a
parentd5d1fb2020f685dc8ada470bded3c708837fb646 (diff)
downloadperfetto-62b8eb7c6ae9f3ef546c35ff741c7cbbfea106a6.tar.gz
Short circuit free(nullptr).
This is needed to prevent a crash that happens when we enable heapprof while Bionic atrace is also enabled. Cherry-pick of c3a91a37e4503eb6537a81c3a17ee3187ae196b7 Bug: 137284735 Test: flash walleye-userdebug profile system_server and concurrently run bionic atrace Change-Id: Ia123a17b7df0790cb82c6c9073ce5638cd1a189f Merged-In: Ia123a17b7df0790cb82c6c9073ce5638cd1a189f
-rw-r--r--src/profiling/memory/malloc_hooks.cc11
1 files changed, 11 insertions, 0 deletions
diff --git a/src/profiling/memory/malloc_hooks.cc b/src/profiling/memory/malloc_hooks.cc
index 6070a03cb..387fd842d 100644
--- a/src/profiling/memory/malloc_hooks.cc
+++ b/src/profiling/memory/malloc_hooks.cc
@@ -501,6 +501,17 @@ int HEAPPROFD_ADD_PREFIX(_posix_memalign)(void** memptr,
// sure that the address is not reused before we've processed the deallocation
// (which includes assigning a sequence id to it).
void HEAPPROFD_ADD_PREFIX(_free)(void* pointer) {
+ // free on a nullptr is valid but has no effect. Short circuit here, for
+ // various advantages:
+ // * More efficient
+ // * Notably printf calls free(nullptr) even when it is used in a way
+ // malloc-free way, as it unconditionally frees the pointer even if
+ // it was never written to.
+ // Short circuiting here makes it less likely to accidentally build
+ // infinite recursion.
+ if (pointer == nullptr)
+ return;
+
const MallocDispatch* dispatch = GetDispatch();
std::shared_ptr<perfetto::profiling::Client> client;
{