Carnegie Mellon
Referencing Nonexistent Variables
Forgetting that local variables disappear when a function returns
int *foo () {
int val;
return &val;
}
1
Carnegie Mellon
Freeing Blocks Multiple Times Nasty!
x = malloc(N*sizeof(int));
free(x);
y = malloc(M*sizeof(int));
free(x);
2
Carnegie Mellon
Referencing Freed Blocks Evil!
x = malloc(N*sizeof(int));
free(x); …
y = malloc(M*sizeof(int));
for (i=0; i
head->next = NULL;
}
…
free(head);
return;
5