Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
model-checker : free pointers
[simgrid.git] / src / xbt / mmalloc / mm_diff.c
index 72e8845..566e7d9 100644 (file)
@@ -204,19 +204,19 @@ int mmalloc_compare_mdesc(struct mdesc *mdp1, struct mdesc *mdp2, void* s_heap,
   int distance = 0;
   int pointer_align;
 
-  char *pointed_address1, *pointed_address2;
+  char *pointed_address1 = NULL, *pointed_address2 = NULL;
 
   /* Check busy blocks*/
 
-  while(i < mdp1->heapindex){
+  while(i < mdp1->heaplimit){
 
     if(mdp1->heapinfo[i].type != mdp2->heapinfo[i].type){
       fprintf(stderr,"Different type of block : %d - %d\n", mdp1->heapinfo[i].type, mdp2->heapinfo[i].type);
       errors++;
     }
 
-    addr_block1 = (char *)mdp1 + sizeof(struct mdesc) + (i * BLOCKSIZE);
-    addr_block2 = (char *)mdp2 + sizeof(struct mdesc) + (i * BLOCKSIZE);
+    addr_block1 = (char *)mdp1 + mdp1->headersize + ((i-1) * BLOCKSIZE);
+    addr_block2 = (char *)mdp2 + mdp2->headersize + ((i-1) * BLOCKSIZE); 
 
     if(mdp1->heapinfo[i].type == 0){ /* busy large block */
 
@@ -247,7 +247,7 @@ int mmalloc_compare_mdesc(struct mdesc *mdp1, struct mdesc *mdp2, void* s_heap,
            fprintf(stderr, "Pointed address : %p (in %s) - %p (in %s)\n", *((void **)((char *)addr_block1 + pointer_align)), pointed_address1, *((void **)((char *)addr_block2 + pointer_align)), pointed_address2);
            if((strcmp(pointed_address1, pointed_address2) == 0) && (strcmp(pointed_address1, "std_heap") == 0)){
              /* FIXME : compare value pointed thanks to DWARF */
-           } 
+           }
          }
        }
 
@@ -258,7 +258,10 @@ int mmalloc_compare_mdesc(struct mdesc *mdp1, struct mdesc *mdp2, void* s_heap,
        errors++;
       }
 
-      i = i + mdp1->heapinfo[i].busy_block.size + 1;
+      if( mdp1->heapinfo[i].busy_block.size == 0)
+       i = i + 1;
+      else
+       i = i + mdp1->heapinfo[i].busy_block.size;
 
     }else{
       
@@ -336,6 +339,8 @@ int mmalloc_compare_mdesc(struct mdesc *mdp1, struct mdesc *mdp2, void* s_heap,
 
   }
 
+  free(pointed_address1);
+  free(pointed_address2);
 
   return (errors);
 }
@@ -354,6 +359,7 @@ const char* get_addr_memory_map(void *addr, void* s_heap, void* r_heap){
     perror("fopen failed");
 
   if(addr == NULL){
+    free(line);
     fclose(fp);
     return "nil";
   }
@@ -376,18 +382,37 @@ const char* get_addr_memory_map(void *addr, void* s_heap, void* r_heap){
     if((addr > start_addr) && ( addr < end_addr)){
       free(line);
       fclose(fp);
-      if(start_addr == s_heap)
+      if(start_addr == s_heap){
+       xbt_dynar_reset(lfields);
+       xbt_free(lfields);
+       xbt_dynar_reset(start_end);
+       xbt_free(start_end);
        return "std_heap";
-      if(start_addr == r_heap)
+      }
+      if(start_addr == r_heap){
+       xbt_dynar_reset(lfields);
+       xbt_free(lfields);
+       xbt_dynar_reset(start_end);
+       xbt_free(start_end);
        return "raw_heap";
-      if(xbt_dynar_length(lfields) == 6)
+      }
+      if(xbt_dynar_length(lfields) == 6){
        return xbt_dynar_get_as(lfields, xbt_dynar_length(lfields) - 1, char*);
-      else
+      }else{
+       xbt_dynar_reset(lfields);
+       xbt_free(lfields);
+       xbt_dynar_reset(start_end);
+       xbt_free(start_end);
        return "Anonymous";
+      }
     }
 
   }
 
+  xbt_dynar_reset(lfields);
+  xbt_free(lfields);
+  xbt_dynar_reset(start_end);
+  xbt_free(start_end);
   free(line);
   fclose(fp);
   return "Unknown area";