Segmentation fault when free
unga888 at yahoo.com
Fri Sep 19 16:17:19 UTC 2008
I'm running FreeBSD 7 on i386. I have a C program compiled with gcc 4.2.1 20070719.
Logically my program is:
a = f1(); /* malloc() and send a string */
b = f2(); /* malloc() and send a string */
c = (char *) malloc(strlen(a) + strlen(b) + 1);
c = '\0';
When it executes free(b), my program exits with Segmentation fault: 11. The free(a) executes well.
The problem is with free(b). Even swap free(b) first and free(a) next, it still crashes at free(b).
If I comment out free() lines, further down the program, first few characters of one string get dropped when executes a completely unrelated line.
How could I bit more narrow down the problem?
Many thanks in advance.
More information about the freebsd-questions