Layers: fix MemTracker threading crash
authorMike Stroyan <mike@LunarG.com>
Mon, 18 May 2015 22:33:03 +0000 (16:33 -0600)
committerMark Lobodzinski <mark@lunarg.com>
Tue, 2 Jun 2015 14:43:17 +0000 (09:43 -0500)
updateFenceTracking was using iterator for deleted item.

layers/mem_tracker.cpp

index d87c8ee..bce0cb8 100644 (file)
@@ -213,7 +213,7 @@ static void updateFenceTracking(
 
     if (fenceMap.size() <= 0)
         return;
-    for (map<uint64_t, MT_FENCE_INFO*>::iterator ii=fenceMap.begin(); !found && ii!=fenceMap.end(); ++ii) {
+    for (map<uint64_t, MT_FENCE_INFO*>::iterator ii=fenceMap.begin(); !found && ii!=fenceMap.end();) {
         if ((*ii).second != NULL) {
             if (fence == ((*ii).second)->fence) {
                 queue = ((*ii).second)->queue;
@@ -221,7 +221,10 @@ static void updateFenceTracking(
                 pQueueInfo->lastRetiredId = (*ii).first;
                 found = true;
             } else {
-                deleteFenceInfo((*ii).first);
+               // Update iterator before deleting item it referred to
+               uint64_t fenceId = (*ii).first;
+               ++ii;
+                deleteFenceInfo(fenceId);
             }
             // Update fence state in fenceCreateInfo structure
             MT_OBJ_INFO* pObjectInfo = getObjectInfo(fence);