From 8196d2cce90dfcafa3fe06534e2b6768a3cd034e Mon Sep 17 00:00:00 2001 From: "Luis A. Lozano" Date: Tue, 19 Sep 2017 17:33:48 -0700 Subject: Fix "use of memory after freed" warning. Static analyzer gets confused in the code to free a linked list. To avoid confusion add an "assert" to tell the analyzer there is no alias between the memory being deleted and accessed. Bug: b/27101951 Test: Warning is gone. Change-Id: Ia6661ee76908c2025b5e1a764d25ba3e11bf44c8 --- libs/binder/MemoryDealer.cpp | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/libs/binder/MemoryDealer.cpp b/libs/binder/MemoryDealer.cpp index 2a15773aa3..1cfe02a3fe 100644 --- a/libs/binder/MemoryDealer.cpp +++ b/libs/binder/MemoryDealer.cpp @@ -289,7 +289,15 @@ SimpleBestFitAllocator::SimpleBestFitAllocator(size_t size) SimpleBestFitAllocator::~SimpleBestFitAllocator() { while(!mList.isEmpty()) { - delete mList.remove(mList.head()); + chunk_t* removed = mList.remove(mList.head()); +#ifdef __clang_analyzer__ + // Clang static analyzer gets confused in this loop + // and generates a false positive warning about accessing + // memory that is already freed. + // Add an "assert" to avoid the confusion. + LOG_ALWAYS_FATAL_IF(mList.head() == removed); +#endif + delete removed; } } -- cgit v1.2.3-59-g8ed1b