0

Valgrind seems to complain with my unload() function, in particular the cursor:

bool unload(void)
{
     node *cursor;
     for (int l = 0; l < 27; l++)
     {
     if (hashtable[l])
     {
          cursor = hashtable[l];
          while (cursor)
          {
               node *temp = cursor;
               cursor = cursor->next;
               free(temp);
          }
      }

   }
   return true;
}

Valgrind outputs: Conditional jump or move depends on uninitialized value, and then points out to "while (cursor)".

1
  • The code seems to work fine for me. Can you please post the valgrind results , the load function and all the global declarations? – Cliff B Dec 23 '18 at 23:19
1

It (probably) indicates that the hashtable array isn't initialized when the node is created. The two common solutions are:

  • Loop through hashtable and set each pointer (element) to null
  • Use calloc instead of malloc

From man calloc

The calloc() function allocates memory for an array of nmemb elements of size bytes each and returns a pointer to the allocated memory. The memory is set to zero. If nmemb or size is 0, then calloc() returns either NULL, or a unique pointer value that can later be successfully passed to free().

You must log in to answer this question.

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