0

Check50 passes on all counts except the valgrind test. This is the message I get:

:( program is free of memory errors valgrind tests failed; rerun with --log for more information.

I have just 8mb left to free, but I can't figure out how to do that. Thanks for your help!

Below are the results of the valgrind test, and here the link to my code: https://gist.github.com/choaimeloo/ffb96f7e43d67e81f0d44c08837f5944.

==3500== HEAP SUMMARY:
==3500==     in use at exit: 8,013,096 bytes in 143,091 blocks
==3500==   total heap usage: 143,093 allocs, 2 frees, 8,014,232 bytes 
allocated
==3500== 
==3500== LEAK SUMMARY:
==3500==    definitely lost: 0 bytes in 0 blocks
==3500==    indirectly lost: 0 bytes in 0 blocks
==3500==      possibly lost: 0 bytes in 0 blocks
==3500==    still reachable: 8,013,096 bytes in 143,091 blocks
==3500==         suppressed: 0 bytes in 0 blocks
==3500== Reachable blocks (those to which a pointer was found) are not shown.
==3500== To see them, rerun with: --leak-check=full --show-leak-kinds=all
==3500== 
==3500== For counts of detected and suppressed errors, rerun with: -v
==3500== ERROR SUMMARY: 0 errors from 0 contexts (suppressed: 0 from 0)



LATEST VALGRIND RESULTS:
==4098== Conditional jump or move depends on uninitialised value(s)
==4098==    at 0x422C22: unload (dictionary.c:139)
==4098==    by 0x421584: main (speller.c:152)
==4098==  Uninitialised value was created by a heap allocation
==4098==    at 0x4C2AB80: malloc (in /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so)
==4098==    by 0x422571: load (dictionary.c:54)
==4098==    by 0x4209B2: main (speller.c:40)
==4098== 
==4098== Conditional jump or move depends on uninitialised value(s)
==4098==    at 0x4C2BDA2: free (in /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so)
==4098==    by 0x422CFF: unload (dictionary.c:145)
==4098==    by 0x421584: main (speller.c:152)
==4098==  Uninitialised value was created by a heap allocation
==4098==    at 0x4C2AB80: malloc (in /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so)
==4098==    by 0x422571: load (dictionary.c:54)
==4098==    by 0x4209B2: main (speller.c:40)
==4098== 

WORDS MISSPELLED:     0
WORDS IN DICTIONARY:  143091
WORDS IN TEXT:        158
TIME IN load:         2.02
TIME IN check:        0.01
TIME IN size:         0.00
TIME IN unload:       0.34
TIME IN TOTAL:        2.36

==4098== 
==4098== HEAP SUMMARY:
==4098==     in use at exit: 0 bytes in 0 blocks
==4098==   total heap usage: 143,093 allocs, 143,093 frees, 8,014,232 bytes 
 allocated
==4098== 
=4098== All heap blocks were freed -- no leaks are possible
==4098== 
==4098== For counts of detected and suppressed errors, rerun with: -v
==4098== ERROR SUMMARY: 19818 errors from 2 contexts (suppressed: 0 from 0)
  • Hi ChoLoo, Ias far as I understood you should not edit your questions to ask new questions. That makes it very hard for other users to understand the questions and answers on this page. You probably should have posted a new question in stead. – Peter Pesch Oct 10 '18 at 5:24
  • I'm quite new myself too, and I don't know the exact rules yet, but I'll assume that I am allowed to answer your follow-up question on this page ... – Peter Pesch Oct 10 '18 at 5:24
  • I'm sorry, I cannot answer the quesion on this page. The version of the code you refer to is not the same as the version of the last valgrind results (which are in fact quite clear ...). And you cannot change the version of your code in this question without making it impossible to understand the previous question and answer. – Peter Pesch Oct 10 '18 at 5:41
  • Could you please post a new question for your latest question? The last valgrind results look as if they require a different answer and/or explanation. And please, could you edit the current question to make your first set of valgrind results more readable (like you did with the first set of valgroind results)? – Peter Pesch Oct 10 '18 at 5:42
  • 1
    Sorry, I guess I made a bit of a mess. The exchanges I've had with you mark only the second time I've used StackExchange. I've cleaned up the first set of valgrind results as requested. But I was actually able to solve the "uninitialised value" issue I was having yesterday. Valgrind didn't like line 54 so I initialized using calloc, and now everything passes check50. Again, thank you so very much for all your help. – ChoLoo Oct 10 '18 at 8:47
1

I see some problems in your implementation of the unload function.

To start with the good part: I think the code with which you free the memory of a linked list is correct. If you would run that code with cursor pointing to the head of a linked list of nodes, it would release the memory of all the nodes of the linked list.

Now let's suppose your hash table looks like this: hash table If cursor would point to the J.Bartlett node, your code would succesfully release all memory of that linked list.

Problem is: There are 11 more linked list that have to be released. In fact, you would have to release all 32 linked lists of this hash table ... (And in your case, you would have to release all 10000 linked lists of your hash table ...


Finally, to quote Cliff B:

If this answers your question, please click on the check mark to accept. Let's keep up on forum maintenance. ;-)

| improve this answer | |
  • Thanks so much, Peter. I'm inching my way along. With your comment/advice, I was able to free every last bit of memory (yay!). But now valgrind gives me other errors: Conditional jump or move depends on uninitialised value(s) and Uninitialised value was created by a heap allocation I'll edit my question above to include the entirety of the results of the valgrind test. I've been trying to correct the errors but could use some help again. – ChoLoo Oct 9 '18 at 20:21

You must log in to answer this question.

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