+ xbt_free(heapinfo1[i].busy_frag.equal_to[j]);
+ }
+ }
+ }
+ }
+
+ i++;
+ }
+
+ XBT_DEBUG("Different blocks or fragments in heap1 : %d", nb_diff1);
+
+ i = 1;
+
+ while(i<heaplimit){
+ if(heapinfo2[i].type == 0){
+ if(heapinfo2[i].busy_block.busy_size > 0){
+ if(heapinfo2[i].busy_block.equal_to == NULL){
+ if(XBT_LOG_ISENABLED(mm_diff, xbt_log_priority_debug)){
+ addr_block2 = ((void*) (((ADDR2UINT(i)) - 1) * BLOCKSIZE + (char*)heapbase2));
+ XBT_DEBUG("Block %zu (%p) not found (size used = %zu)", i, addr_block2, heapinfo2[i].busy_block.busy_size);
+ mmalloc_backtrace_block_display((void*)heapinfo2, i);
+ }
+ nb_diff2++;
+ }else{
+ xbt_free(heapinfo2[i].busy_block.equal_to);
+ }
+ }
+ }
+ if(heapinfo2[i].type > 0){
+ addr_block2 = ((void*) (((ADDR2UINT(i)) - 1) * BLOCKSIZE + (char*)heapbase2));
+ for(j=0; j < (size_t) (BLOCKSIZE >> heapinfo2[i].type); j++){
+ if(heapinfo2[i].busy_frag.frag_size[j] > 0){
+ if(heapinfo2[i].busy_frag.equal_to[j] == NULL){
+ if(XBT_LOG_ISENABLED(mm_diff, xbt_log_priority_debug)){
+ addr_frag2 = (void*) ((char *)addr_block2 + (j << heapinfo2[i].type));
+ XBT_DEBUG( "Block %zu, Fragment %zu (%p) not found (size used = %d)", i, j, addr_frag2, heapinfo2[i].busy_frag.frag_size[j]);
+ mmalloc_backtrace_fragment_display((void*)heapinfo2, i, j);
+ }
+ nb_diff2++;
+ }else{
+ xbt_free(heapinfo2[i].busy_frag.equal_to[j]);
+ }
+ }
+ }
+ }
+ i++;
+ }
+
+ XBT_DEBUG("Different blocks or fragments in heap2 : %d", nb_diff2);
+
+ xbt_dynar_free(&previous);
+ ignore_done = 0;
+ s_heap = NULL, heapbase1 = NULL, heapbase2 = NULL;
+ heapinfo1 = NULL, heapinfo2 = NULL;
+ heaplimit = 0, heapsize1 = 0, heapsize2 = 0;
+
+ return ((nb_diff1 > 0) || (nb_diff2 > 0));
+}
+
+static heap_area_t new_heap_area(int block, int fragment){
+ heap_area_t area = NULL;
+ area = xbt_new0(s_heap_area_t, 1);
+ area->block = block;
+ area->fragment = fragment;
+ return area;
+}
+
+static int in_mc_comparison_ignore(int block, int fragment){
+
+ unsigned int cursor = 0;
+ int start = 0;
+ int end = xbt_dynar_length(mc_heap_comparison_ignore) - 1;
+ mc_heap_ignore_region_t region;
+
+ while(start <= end){
+ cursor = (start + end) / 2;
+ region = (mc_heap_ignore_region_t)xbt_dynar_get_as(mc_heap_comparison_ignore, cursor, mc_heap_ignore_region_t);
+ if(region->block == block){
+ if(region->fragment == fragment)
+ return 1;
+ if(region->fragment < fragment)
+ start = cursor + 1;
+ if(region->fragment > fragment)
+ end = cursor - 1;
+ }
+ if(region->block < block)
+ start = cursor + 1;
+ if(region->block > block)
+ end = cursor - 1;
+ }
+
+ return 0;
+}
+
+static size_t heap_comparison_ignore_size(void *address){
+ unsigned int cursor = 0;
+ int start = 0;
+ int end = xbt_dynar_length(mc_heap_comparison_ignore) - 1;
+ mc_heap_ignore_region_t region;
+
+ while(start <= end){
+ cursor = (start + end) / 2;
+ region = (mc_heap_ignore_region_t)xbt_dynar_get_as(mc_heap_comparison_ignore, cursor, mc_heap_ignore_region_t);
+ if(region->address == address)
+ return region->size;
+ if(region->address < address)
+ start = cursor + 1;
+ if(region->address > address)
+ end = cursor - 1;
+ }
+
+ return 0;
+}
+
+
+static int compare_area(void *area1, void* area2, size_t size, xbt_dynar_t previous, int check_ignore){
+
+ size_t i = 0, pointer_align = 0, ignore1 = 0, ignore2 = 0;
+ void *address_pointed1, *address_pointed2, *addr_block_pointed1, *addr_block_pointed2, *addr_frag_pointed1, *addr_frag_pointed2;
+ size_t block_pointed1, block_pointed2, frag_pointed1, frag_pointed2;
+ int res_compare;
+ void *current_area1, *current_area2;
+
+ while(i<size){
+
+ if(check_ignore){
+
+ current_area1 = (char*)((xbt_mheap_t)s_heap)->heapbase + ((((char *)area1) + i) - (char *)heapbase1);
+ if((ignore1 = heap_comparison_ignore_size(current_area1)) > 0){
+ current_area2 = (char*)((xbt_mheap_t)s_heap)->heapbase + ((((char *)area2) + i) - (char *)heapbase2);
+ if((ignore2 = heap_comparison_ignore_size(current_area2)) == ignore1){
+ i = i + ignore2;
+ ignore_done++;
+ continue;
+ }
+ }
+
+ }
+
+ if(memcmp(((char *)area1) + i, ((char *)area2) + i, 1) != 0){
+
+ /* Check pointer difference */
+ pointer_align = (i / sizeof(void*)) * sizeof(void*);
+ address_pointed1 = *((void **)((char *)area1 + pointer_align));
+ address_pointed2 = *((void **)((char *)area2 + pointer_align));
+
+ /* Get pointed blocks number */
+ block_pointed1 = ((char*)address_pointed1 - (char*)((xbt_mheap_t)s_heap)->heapbase) / BLOCKSIZE + 1;
+ block_pointed2 = ((char*)address_pointed2 - (char*)((xbt_mheap_t)s_heap)->heapbase) / BLOCKSIZE + 1;
+
+ /* Check if valid blocks number */
+ if((char *)address_pointed1 < (char*)((xbt_mheap_t)s_heap)->heapbase || block_pointed1 > heapsize1 || block_pointed1 < 1 || (char *)address_pointed2 < (char*)((xbt_mheap_t)s_heap)->heapbase || block_pointed2 > heapsize2 || block_pointed2 < 1)
+ return 1;
+
+ if(heapinfo1[block_pointed1].type == heapinfo2[block_pointed2].type){ /* Same type of block (large or fragmented) */
+
+ addr_block_pointed1 = ((void*) (((ADDR2UINT(block_pointed1)) - 1) * BLOCKSIZE + (char*)heapbase1));
+ addr_block_pointed2 = ((void*) (((ADDR2UINT(block_pointed2)) - 1) * BLOCKSIZE + (char*)heapbase2));
+
+ if(heapinfo1[block_pointed1].type == 0){ /* Large block */
+
+ if(heapinfo1[block_pointed1].busy_block.size != heapinfo2[block_pointed2].busy_block.size){
+ return 1;
+ }
+
+ if(heapinfo1[block_pointed1].busy_block.busy_size != heapinfo2[block_pointed2].busy_block.busy_size){
+ return 1;
+ }
+
+ if(add_heap_area_pair(previous, block_pointed1, -1, block_pointed2, -1)){
+
+ if(ignore_done < xbt_dynar_length(mc_heap_comparison_ignore)){
+ if(in_mc_comparison_ignore(block_pointed1, -1))
+ res_compare = compare_area(addr_block_pointed1, addr_block_pointed2, heapinfo1[block_pointed1].busy_block.busy_size, previous, 1);
+ else
+ res_compare = compare_area(addr_block_pointed1, addr_block_pointed2, heapinfo1[block_pointed1].busy_block.busy_size, previous, 0);