Ejemplo n.º 1
0
 ~CheckMemoryLeaks(void) {
     if (! isSaneHeap()) {
         printf("oh goodness! you've corrupted the heap, naughty naughty\n");
         return;
     }
     if (! isEmptyHeap()) {
         printf("Uh Oh! you have a memory leak somewhere, better find it\n");
         return;
     }
     printf("The heap is all clean, good work!\n");
 }
void testStage4(void) {
	char p[20];
	if (! isSaneHeap()) {
		printf("oh goodness! you've corrupted the heap, naughty naughty\n");
		return;
	}
	if (! isEmptyHeap()) {
		printf("Uh Oh! you have a memory leak somewhere, better find it\n");
		return;
	}	
	/* if we reach this point, the heap is OK */
	printf("woo HOO! the heap is OK, test 4 looks good so far, now we're going to crash...\n");
	/* each of the following lines should crash the program (an assert should fail) 
	 * try each of them in turn to make sure you're catching the obvious mistakes 
	 * just uncomment the line and see what happens (it should crash) 
	 */
	 printf("crashing with utstrlen\n\n\n"); utstrlen("Hello World");	
	 printf("crashing with utstrcpy\n\n\n"); utstrcpy(p, "Hello World");
	 printf("crashing with utstrcat\n\n\n"); utstrcat(p, "Hello World");
	 printf("crashing with utstrfree\n\n\n"); utstrfree((char *)malloc(20));
	 printf("crashing with utstrrealloc\n\n\n"); utstrrealloc((char *)malloc(20), 40);
}