0

For my pset5 speller program valgrind is saying that i have still reachable memory. This is the output:

HEAP SUMMARY:

==24516== in use at exit: 352 bytes in 1 blocks

==24516== total heap usage: 367,084 allocs, 367,083 frees, 41,113,888 bytes allocated

==24516==

==24516== 352 bytes in 1 blocks are still reachable in loss record 1 of 1

==24516== at 0x402A17C: malloc (in /usr/lib/valgrind/vgpreload_memcheck-x86-linux.so)

==24516== by 0x40A8D1B: __fopen_internal (iofopen.c:73)

==24516== by 0x40A8DFA: fopen@@GLIBC_2.1 (iofopen.c:103)

==24516== by 0x8049090: load (dictionary.c:55)

==24516== by 0x8048755: main (speller.c:45)

I take this to mean I am opining a file and not closing it. This is line 55 in load:

FILE* dp = fopen(dictionary, "r");

However at the end of load I have this line:

fclose(dp);

So I don't understand what the issue is.

1
  • I am getting a similar error. Please can you tell me how you solved the issue? I am very frustrated with it. Here's a link to my question - Pset5 Speller Valgrind error cs50.stackexchange.com/q/26730/19864?sem=2
    – noob
    Commented Aug 30, 2017 at 22:49

1 Answer 1

-1

Had a similar error and found a file still open. I do see a difference though, I didn't get any mention of malloc like you had.

==24516== at 0x402A17C: malloc (in /usr/lib/valgrind/vgpreload_memcheck-x86-linux.so)

if you can't find a file open maybe look into where you are using malloc.
Here was my error

==6562== HEAP SUMMARY:
==6562==     in use at exit: 568 bytes in 1 blocks
==6562==   total heap usage: 367,084 allocs, 367,083 frees, 82,227,504 bytes     allocated
==6562== 
==6562== LEAK SUMMARY:
==6562==    definitely lost: 0 bytes in 0 blocks
==6562==    indirectly lost: 0 bytes in 0 blocks
==6562==      possibly lost: 0 bytes in 0 blocks
==6562==    still reachable: 568 bytes in 1 blocks
==6562==         suppressed: 0 bytes in 0 blocks
==6562== Reachable blocks (those to which a pointer was found) are not     shown.
==6562== To see them, rerun with: --leak-check=full --show-leak-kinds=all
==6562== 
==6562== For counts of detected and suppressed errors, rerun with: -v
==6562== ERROR SUMMARY: 0 errors from 0 contexts (suppressed: 0 from 0)
1
  • Welcome to CS50! I down voted your answer because you responded to an older question (from 2015) but your answer seems like a guess and does not offer a clear solution. Readers are not likely to gain benefit from this answer. A better approach when you are unsure would be to comment on the question, requesting the asker to provide source code or other information. Commented Jul 7, 2016 at 22:26

You must log in to answer this question.

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