My code is leaking just 276 bytes of memory in pset 5, and I am at a loss to understanding where it is.
Using help50 and valgrind, I get the advice:
Looks like your program leaked 276 bytes of memory. Did you forget to free memory that you allocated via malloc? Take a closer look at line 40 of dictionary.c.
The summary of the leakage is: ==10620== HEAP SUMMARY: ==10620== in use at exit: 276 bytes in 6 blocks ==10620== total heap usage: 143,103 allocs, 143,097 frees, 8,023,683 bytes allocated ==10620== ==10620== 276 bytes in 6 blocks are definitely lost in loss record 1 of 1
bool check(const char *word)
{
char *temp_string = malloc(LENGTH + 1); //this is line 40.
int k = 0;
strcpy(temp_string, word);
while (*(word + k) != (char) 0)
{
*(temp_string + k) = tolower(*(temp_string + k));
k++;
}
if (table[hash(temp_string)] == NULL)
{
return false;
}
else
{
return is_in(table[hash(temp_string)], temp_string);
}
free(temp_string);
}