Fixed Michael's allocator termination: in rare case a reading of freed memory is...
authorkhizmax <khizmax@gmail.com>
Tue, 21 Jun 2016 16:05:22 +0000 (19:05 +0300)
committerkhizmax <khizmax@gmail.com>
Tue, 21 Jun 2016 16:05:22 +0000 (19:05 +0300)
cds/memory/michael/allocator.h

index 678631e4366120fa34ba9ca3a260209baa93b908..c2fd4fc57b6a0faa31a9967a603ba32b1bee4a44 100644 (file)
@@ -1566,8 +1566,21 @@ namespace michael {
         {
             const size_t nPageHeapCount = m_SizeClassSelector.pageTypeCount();
 
-            for (unsigned int j = 0; j < m_SizeClassSelector.size(); ++j )
-                free_processor_heap( pDesc->arrProcHeap + j );
+            {
+                processor_heap * const pProcHeapEnd = pDesc->arrProcHeap + m_SizeClassSelector.size();
+
+                // In first, free small blocks
+                for ( processor_heap * pProcHeap = pDesc->arrProcHeap; pProcHeap < pProcHeapEnd; ++pProcHeap ) {
+                    if ( pProcHeap->nPageIdx == processor_heap::c_nPageSelfAllocation )
+                        free_processor_heap( pProcHeap );
+                }
+
+                // free large blocks
+                for ( processor_heap * pProcHeap = pDesc->arrProcHeap; pProcHeap < pProcHeapEnd; ++pProcHeap ) {
+                    if ( pProcHeap->nPageIdx != processor_heap::c_nPageSelfAllocation )
+                        free_processor_heap( pProcHeap );
+                }
+            }
 
             for ( superblock_desc * pSBDesc = pDesc->listSBDescFree.pop(); pSBDesc; pSBDesc = pDesc->listSBDescFree.pop())
                 m_AlignedHeap.free( pSBDesc );