Why would I get a bus error or segmentation fault when calling free() normally?
- by chucknelson
I have a very simple test program, running on Solaris 5.8:
#include <stdio.h>
#include <stdlib.h>
int main(void)
{
char *paths;
paths = getenv("PATH");
printf("Paths: %s\n", paths);
free(paths); // this causes a bus error
return 0;
}
If I don't call free() at the end, it displays the message fine and exits. If…