I get the following error on running speller.c:

double free or corruption (fasttop): 0x084a7008

enter image description here

And this is what running Valgrind gives: enter image description here

I understand that this error occurs on trying to free already freed space or on writing more bytes to memory space that has been allocated less. I think this is occurring because of using free in Unload() because otherwise the program runs fine if I comment out the code in Unload() and simply return True. Not sure what I'm doing wrong in unload().

bool unload(void)
    node* cursor = NULL;
    node* temp = NULL;

    for (int i = 0; i < HashTable_Size; i++)
         cursor = hashtable[i];

         while (cursor != NULL)
             temp = cursor;
             cursor = cursor->next;

         hashtable[i] = NULL;

    return true;
  • Apparently, this has nothing to do with your unload() function. Where else are you calling free() in your code?
    – kzidane
    Aug 7 '14 at 13:02
  • Not calling free() anywhere else. Aug 7 '14 at 13:08
  • Please make sure you're not calling it twice anywhere because I just tried your function with a sample program and it works as expected. Here's a screenshot!
    – kzidane
    Aug 7 '14 at 13:13
  • Searched through the dictionary.c program. Not calling it anywhere else :( Anything else that might be causing the issue? Aug 7 '14 at 13:37
  • 2
    Is it possible that there is a circular reference in the linked list? If cursor->next points back to another node in the list that has already been freed then you will see the double free error. Check the code that inserts nodes into the list, or print out the linked list. Also try run this with valgrind to get a clearer error message. Aug 7 '14 at 14:03

So finally I got to it work. Not quite sure what the issue was. My guess is that before I was allocating memory for the node outside 'if else' conditions block in Load(). I inserted the following line in if and else statement block and it works now.

node* new_node = malloc(sizeof(node));

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .