[Lldb-commits] [lldb] 9d4415d - Don't refer to allocation map entry after deallocating it

Jason Molenda via lldb-commits lldb-commits at lists.llvm.org
Thu Apr 15 20:16:47 PDT 2021


Author: Jason Molenda
Date: 2021-04-15T20:16:38-07:00
New Revision: 9d4415d01d234efb5dd46bdcbb280c03e12a8101

URL: https://github.com/llvm/llvm-project/commit/9d4415d01d234efb5dd46bdcbb280c03e12a8101
DIFF: https://github.com/llvm/llvm-project/commit/9d4415d01d234efb5dd46bdcbb280c03e12a8101.diff

LOG: Don't refer to allocation map entry after deallocating it

debugserver's MachTask::DeallocateMemory when removing an
allocate entry from our map (in resposne to an '_m' packet),
copy the size from the entry before removing it from the
map and then using the iterator to fix an ASAN error on
the bots when running TestGdbRemoteMemoryAllocation.py

rdar://76595998

Added: 
    

Modified: 
    lldb/tools/debugserver/source/MacOSX/MachTask.mm

Removed: 
    


################################################################################
diff  --git a/lldb/tools/debugserver/source/MacOSX/MachTask.mm b/lldb/tools/debugserver/source/MacOSX/MachTask.mm
index 7c46ec8d5ecd9..767dc59b67808 100644
--- a/lldb/tools/debugserver/source/MacOSX/MachTask.mm
+++ b/lldb/tools/debugserver/source/MacOSX/MachTask.mm
@@ -984,15 +984,15 @@ static void get_threads_profile_data(DNBProfileDataScanType scanType,
   allocation_collection::iterator pos, end = m_allocations.end();
   for (pos = m_allocations.begin(); pos != end; pos++) {
     if ((*pos).first == addr) {
+      size_t size = (*pos).second;
       m_allocations.erase(pos);
 #define ALWAYS_ZOMBIE_ALLOCATIONS 0
       if (ALWAYS_ZOMBIE_ALLOCATIONS ||
           getenv("DEBUGSERVER_ZOMBIE_ALLOCATIONS")) {
-        ::mach_vm_protect(task, (*pos).first, (*pos).second, 0, VM_PROT_NONE);
+        ::mach_vm_protect(task, addr, size, 0, VM_PROT_NONE);
         return true;
       } else
-        return ::mach_vm_deallocate(task, (*pos).first, (*pos).second) ==
-               KERN_SUCCESS;
+        return ::mach_vm_deallocate(task, addr, size) == KERN_SUCCESS;
     }
   }
   return false;


        


More information about the lldb-commits mailing list