0

I've successfully completed my program, but since this is my first time working with malloc() and free(), I wanted to make sure that I understood what valgrind was giving me as feedback. So first off in the command line I input:

 help50 valgrind --leak-check=full --show-leak-kinds=all ./speller texts/ralph.txt

which returns the output i've placed below this text, but I'm just trying to understand what the thing is actually saying. As I understand the output, the leak summary at the end indicates that I've leaked no memory in my process. Good. But what would it have meant if I had 'indirectly lost' or 'possibly lost' something? What does it mean that X number of bytes are still reachable? Why does it say, in heap usage, that there have been 367,084 allocs, and only 2 frees (I'm assuming this is counting the number of calls, or something similar), when I know that I'm successfully freeing all of my memory, and that implies calling free many more times than 2?

==3106== Memcheck, a memory error detector
==3106== Copyright (C) 2002-2013, and GNU GPL'd, by Julian Seward et al.
==3106== Using Valgrind-3.10.1 and LibVEX; rerun with -h for copyright info
==3106== Command: ./speller texts/ralph.txt
==3106== 
143091 total words saved

MISSPELLED WORDS

Wiggum
Could not unload dictionaries/large.
==3106== 
==3106== HEAP SUMMARY:
==3106==     in use at exit: 82,226,368 bytes in 367,082 blocks
==3106==   total heap usage: 367,084 allocs, 2 frees, 82,227,504 bytes allocated
==3106== 
==3106== 224 bytes in 1 blocks are still reachable in loss record 1 of 3
==3106==    at 0x4C2AB80: malloc (in /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so)
==3106==    by 0x401493: get_node (dictionary.c:184)
==3106==    by 0x40127A: load (dictionary.c:97)
==3106==    by 0x40094D: main (speller.c:40)
==3106== 
==3106== 1,916,768 bytes in 8,557 blocks are still reachable in loss record 2 of 3
==3106==    at 0x4C2AB80: malloc (in /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so)
==3106==    by 0x401493: get_node (dictionary.c:184)
==3106==    by 0x40137B: load (dictionary.c:134)
==3106==    by 0x40094D: main (speller.c:40)
==3106== 
==3106== 80,309,376 bytes in 358,524 blocks are still reachable in loss record 3 of 3
==3106==    at 0x4C2AB80: malloc (in /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so)
==3106==    by 0x401493: get_node (dictionary.c:184)
==3106==    by 0x401311: load (dictionary.c:120)
==3106==    by 0x40094D: main (speller.c:40)
==3106== 
==3106== LEAK SUMMARY:
==3106==    definitely lost: 0 bytes in 0 blocks
==3106==    indirectly lost: 0 bytes in 0 blocks
==3106==      possibly lost: 0 bytes in 0 blocks
==3106==    still reachable: 82,226,368 bytes in 367,082 blocks
==3106==         suppressed: 0 bytes in 0 blocks
==3106== 
==3106== For counts of detected and suppressed errors, rerun with: -v
==3106== ERROR SUMMARY: 0 errors from 0 contexts (suppressed: 0 from 0)

Sorry, not sure how to help (yet) with this one! 
2
  • I know that I'm successfully freeing all of my memory and the output reads Could not unload dictionaries/large.?
    – Blauelf
    Apr 12 '17 at 12:08
  • I had only implemented my function to free memory, which was an external function. "unload" is a function that returns a boolean. I hadn't yet written anything to change the return value of unload, and so in speller it printed 'could not unload dictionaries/large' although the dictionary had in fact been freed.
    – ItsAnApe
    Apr 12 '17 at 14:25
0

The different types of leaks are explained in the Valgrind FAQ and manual.

The two calls of free are probably inside fclose.

You must log in to answer this question.

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