2

I got Pset5 Speller to work correctly but I am getting a Valgrind error as follows 568 bytes in 1 blocks are still reachable in loss record 1 of 1: (file: dictionary.c, line: 108) for all the words. What could be the problem?

Line 108 is in the load function where I am opening the dictionary

bool load(const char *dictionary)
{
    FILE* fp = fopen(dictionary, "r");  #108
........... fclose(fp);
    return false;
}

help50 output-

==11836== 
==11836== HEAP SUMMARY:
==11836==     in use at exit: 568 bytes in 1 blocks
==11836==   total heap usage: 367,084 allocs, 367,083 frees, 82,227,504 bytes allocated
==11836== 
==11836== LEAK SUMMARY:
==11836==    definitely lost: 0 bytes in 0 blocks
==11836==    indirectly lost: 0 bytes in 0 blocks
==11836==      possibly lost: 0 bytes in 0 blocks
==11836==    still reachable: 568 bytes in 1 blocks
==11836==         suppressed: 0 bytes in 0 blocks
==11836== Reachable blocks (those to which a pointer was found) are not shown.
==11836== To see them, rerun with: --leak-check=full --show-leak-kinds=all
==11836== 
==11836== For counts of detected and suppressed errors, rerun with: -v
==11836== ERROR SUMMARY: 0 errors from 0 contexts (suppressed: 0 from 0)

Sorry, not sure how to help (yet) with this one!

1 Answer 1

3

Without seeing more code, it's hard to know. A leak of 568 bytes in 1 block usually indicates a file that wasn't closed. Is it possible that there's a return command executed before the dictionary file was closed?

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

1
  • Yes! I was returning true in an if condition before closing the file! Thank you so much :D
    – noob
    Commented Aug 30, 2017 at 23:25

You must log in to answer this question.

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