0

I'm doing PSET4 SPELLER, My code is working properly but Valgrind is giving errors, I'm unable to figure out why so.
valgrind

32 bytes in 1 blocks are still reachable in loss record 1 of 1 

Re-checked the code couple of times, things I have done
1) Open and close dictionary (using fopen and fclose)
2) malloc space to "newptr", did not free as it needs to be added to the hashtable
3) created a node cursor and temp, free-ed both
4) created some other nodes, free-ed temporary ones.

[removed code per academic honesty]
0
1

The 32 bytes you mention are a duplicate of pset4 speller - can't pass valgrind test - 32 bytes still reachable

However, you didn't mention that you free nodes in check, nodes still in use, being part of a linked list. There should not be a free in that function.

Edit: Just realized that your loop in check is even worse. In case of using the small dictionary, hashtable[hash(word)] might be NULL, and you'd access NULL->word, segmentation fault.

To fix this, invert your loop's structure, turn it inside out. Loop as long as temp != NULL, and inside the loop, compare the value and return true on a match, and false after the loop.

2
  • I free temp in check just before returning false as the program ends there. – Rohit Jain Jul 15 '19 at 17:24
  • temp would refer to the node having a matching word member. – Blauelf Jul 15 '19 at 19:06

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