/* Last modified: 25 February 2007 */ #include #include void get_mem() { char *ptr; ptr = (char *) malloc (10); /* memory not freed */ return; // lines added 2/25/07 to test unreachable code free(ptr); } int main(void) { char *ptr1, *ptr2; int i; ptr1 = (char *) malloc (512); ptr2 = (char *) malloc (512); ptr2 = ptr1; /* causes the memory leak of ptr2 */ free(ptr2); free(ptr1); /* double free of same pointer */ *ptr1 = 0; /* write to freed location */ for ( i = 0; i < 512; i++) { get_mem(); } return 0; }