1 2 #include <stdlib.h> 3 #include <sys/types.h> 4 #include <unistd.h> 5 #include <assert.h> 6 do_child_badness(char * p)7void do_child_badness ( char* p ) 8 { 9 /* Free it a second time */ 10 free(p); 11 } 12 do_parent_badness(char * p)13void do_parent_badness ( char* p ) 14 { 15 /* Do a write off the end */ 16 p[10] = 42; 17 } 18 19 main(void)20int main ( void ) 21 { 22 pid_t child; 23 char* p = malloc(10); assert(p); 24 free(p); 25 26 /* parent does something bad */ 27 p[5] = 22; 28 29 child = fork(); 30 assert(child != -1); /* assert fork did not fail */ 31 32 if (child == 0) { 33 /* I am the child */ 34 do_child_badness(p); 35 } else { 36 /* I am the parent */ 37 do_parent_badness(p); 38 } 39 40 return 0; 41 42 } 43