Open awmc000 opened 1 year ago
Regarding the biggest leak: I call the function to empty out that hash table:
hashtable_delete(proper_nouns);
But it doesn't seem to do anything.
void hashtable_delete(struct hash_table *ht)
{
int freed = 0;
for (unsigned int i; i < ht->array_size; i++)
{
if (ht->strings[i] != NULL)
{
free(ht->strings[i]);
ht->array_elems--;
freed++;
}
}
printf("Freed %d strings from a ht with %d elems"
"and total size %d.\n", freed,
ht->array_elems, ht->array_size);
}
Here is the print from that particular hash table.
Freed 0 strings from a ht with 5742 elems and total size 11484.
It works for the other hash table!
Freed 14921 strings from a ht with 0 elems [remaining] and total size 29842.
Fixed the biggest leak. hashtable_delete
had an uninitialized counter i
.
==2004179== Memcheck, a memory error detector
==2004179== Copyright (C) 2002-2017, and GNU GPL'd, by Julian Seward et al.
==2004179== Using Valgrind-3.18.1 and LibVEX; rerun with -h for copyright info
==2004179== Command: ./readability testdata/oneline
==2004179==
testdata/oneline
lists/dale-expanded loaded successfully.
lists/proper-nouns loaded successfully.
==2004179== Conditional jump or move depends on uninitialised value(s)
==2004179== at 0x48FB18B: getdelim (iogetdelim.c:59)
==2004179== by 0x10A3CB: assess_readability (in /home/alex/Programming/C/readability/readability)
==2004179== by 0x109421: main (main.c:20)
==2004179==
Freed 14921 strings from a ht with 0 elemsand total size 29842.
Freed 5742 strings from a ht with 0 elemsand total size 11484.
Dale-Chall score of 0.25
Breakdown: 0 hard of 5 words, 1 sentences.
avg. 5 words per sentence. 0.00% difficult words.
Easily understood by an average student in 4th grade or lower
Computed score in 212.8100 ms.
==2004179==
==2004179== HEAP SUMMARY:
==2004179== in use at exit: 1,240 bytes in 4 blocks
==2004179== total heap usage: 20,793 allocs, 20,789 frees, 1,017,780 bytes allocated
==2004179==
==2004179== 256 bytes in 1 blocks are definitely lost in loss record 1 of 4
==2004179== at 0x484DA83: calloc (in /usr/libexec/valgrind/vgpreload_memcheck-amd64-linux.so)
==2004179== by 0x10A1E1: assess_readability (in /home/alex/Programming/C/readability/readability)
==2004179== by 0x109421: main (main.c:20)
==2004179==
==2004179== 256 bytes in 1 blocks are definitely lost in loss record 2 of 4
==2004179== at 0x484DA83: calloc (in /usr/libexec/valgrind/vgpreload_memcheck-amd64-linux.so)
==2004179== by 0x10986C: hashtable_load_words_from_file (hash_table.c:137)
==2004179== by 0x10A0FC: get_table_from_list_file (in /home/alex/Programming/C/readability/readability)
==2004179== by 0x10A22B: assess_readability (in /home/alex/Programming/C/readability/readability)
==2004179== by 0x109421: main (main.c:20)
==2004179==
==2004179== 256 bytes in 1 blocks are definitely lost in loss record 3 of 4
==2004179== at 0x484DA83: calloc (in /usr/libexec/valgrind/vgpreload_memcheck-amd64-linux.so)
==2004179== by 0x10986C: hashtable_load_words_from_file (hash_table.c:137)
==2004179== by 0x10A0FC: get_table_from_list_file (in /home/alex/Programming/C/readability/readability)
==2004179== by 0x10A243: assess_readability (in /home/alex/Programming/C/readability/readability)
==2004179== by 0x109421: main (main.c:20)
==2004179==
==2004179== LEAK SUMMARY:
==2004179== definitely lost: 768 bytes in 3 blocks
==2004179== indirectly lost: 0 bytes in 0 blocks
==2004179== possibly lost: 0 bytes in 0 blocks
==2004179== still reachable: 472 bytes in 1 blocks
==2004179== suppressed: 0 bytes in 0 blocks
==2004179== Reachable blocks (those to which a pointer was found) are not shown.
==2004179== To see them, rerun with: --leak-check=full --show-leak-kinds=all
==2004179==
==2004179== Use --track-origins=yes to see where uninitialised values come from
==2004179== For lists of detected and suppressed errors, rerun with: -s
==2004179== ERROR SUMMARY: 4 errors from 4 contexts (suppressed: 0 from 0)
still need to fix line buffer leaks and possible uninitialized values elsewhere.
There are memory leaks in the program. In particular it appears that line buffers and words in word lists (represented by hash tables) are not being freed. I have fixed a couple of the leaks but most including the biggest remain. When testing I use a single line of text with 5 words, the minimum data for a readability score. Note: 5,742 blocks are lost in the biggest leak. This is the exact number of proper nouns on the current list.
Here is the section of the report on the most egregious leak:
Here is the full report: