From: khizmax Date: Tue, 21 Jun 2016 16:05:22 +0000 (+0300) Subject: Fixed Michael's allocator termination: in rare case a reading of freed memory is... X-Git-Tag: v2.2.0~205 X-Git-Url: http://demsky.eecs.uci.edu/git/?a=commitdiff_plain;h=5545d7e6d493b38d3c9028ad3460c665368cd44e;p=libcds.git Fixed Michael's allocator termination: in rare case a reading of freed memory is possible --- diff --git a/cds/memory/michael/allocator.h b/cds/memory/michael/allocator.h index 678631e4..c2fd4fc5 100644 --- a/cds/memory/michael/allocator.h +++ b/cds/memory/michael/allocator.h @@ -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 );