Take the 2-minute tour ×

I do realize there are some "glibc detected" posts but I would be very grateful if you could suggest a solution for this:

*** glibc detected *** ./a.out: double free or corruption (top): 0x08901d70 ***

This seems to happen when I attempt to free a binary search tree:

void freetree(BNODEPTR *root)

The structure is typedef'd to BNODEPTR

struct bnode{
        int info;
        int count;
        struct bnode* left;
        struct bnode* right;

I am calling the function from main() using freetree(root).

The tree seems to be implemented correctly as an inorder traversal produces a sorted output.

The entire code is at:

http://pastebin.com/Eieu3xDa and


share|improve this question
add comment

1 Answer

up vote 3 down vote accepted

I could sift through your source code, but as they say, "Feed a man a fish..."

  1. Compile your code with debugging symbols (pass -g to the compiler). If you do this, you can get a function name instead of ./a.out[0x8048998] in the backtrace.

  2. Run your code with Valgrind's memcheck tool (the default tool). This might give you a much better clue about where the error is. You can just install Valgrind and run valgrind ./a.out for starters.

In particular, I think the whole binary tree is a red herring. There is another problem in your program somewhere else. From the backtrace, I can see that (1) the error message is not triggered in freetree and (2) you are using threads, which are easily misused.

share|improve this answer
After compiling with the -g option I get the output: pastebin.com/pzXTS9Qf. The output of valgrind ./a.out is pastebin.com/nZYJLmUF. I'm not sure I see the actual function name :( –  Monty Swanson Oct 24 '11 at 13:21
@Chhama: Looks like there are no errors to me. Are you sure you got an error when running ./a.out? –  Dietrich Epp Oct 24 '11 at 13:23
yes, and the program got aborted everytime. –  Monty Swanson Oct 24 '11 at 13:26
Run the program in gdb and put a breakpoint on malloc_error_break. It looks like fclose may be getting called more than once on the same file. –  Dietrich Epp Oct 24 '11 at 13:32
thanks. will do –  Monty Swanson Oct 24 '11 at 13:50
add comment

Your Answer


