1

I am trying to understand how heap consistency checking works in GNU C Library. I Refered http://www.gnu.org/software/libc/manual/html_node/Heap-Consistency-Checking.html#Heap-Consistency-Checking

Here is a sample program I have written. I expected as suggested in the manual if I run in gdb and call mcheck(0) my custom abortfn would be called. But it isnt getting called. What am I missing here ? Thanks :)

#include<stdio.h>                                                               
#include<stdlib.h>                                                              
#include<mcheck.h>                                                              

void *abortfn(enum mcheck_status status)                                        
{                                                                               
    switch(status) {                                                            
        case MCHECK_DISABLED:                                                   
            printf("MEMCHECK DISABLED\n");                                      
            break;                                                              
        default:                                                                
            printf("MEMCHECK ENABLED\n");                                       
    }                                                                           
}                                                                               

int main()                                                                      
{                                                                               
    printf("This is mcheck testing code\n");                                    
    int *a = (int *) malloc(sizeof(int));                                       
    *a = 10;                                                                    
    printf("A: %d\n", *a);                                                      
    free(a); 
    return 0;
}
vinodkri
  • 33
  • 4

0 Answers0