5
votes
Accepted
Memory leak in Pset4
Actually, your apparent problem is that you are running valgrind against a different executable binary, also called resize.
~/workspace/ $ which resize
/usr/bin/resize
~/workspace/ $ whatis resize
...
3
votes
Accepted
speller valgrind "uninitialized error was created by heap allocation"
Your new_node -> next is not initialised if it's the first node of a list. malloc allocates memory, but does not guarantee any content, you will get whatever was there before (likely all zeros if ...
3
votes
Accepted
Pset5 Speller Valgrind error
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 ...
3
votes
Accepted
CS50 pset5 Memory Leak (trie structure)
for (int i = 0; i < 26; i++)
You have 27 elements (a-z and '), so <=26 or <27 would be appropriate.
2
votes
Accepted
Valgrind memory leak, WORDS MISSPELLED: 1 pset5
Why are you mallocing space in check?
Also, your free(checker) only runs if the word is not found. How about when the word is found? You return true and the function ends, so that free line is ...
2
votes
How is my (custom) program leaking memory? I am preparing myself for pset5
You don't free the realloced memory. Your code
buffer_temp_word = NULL;
free(buffer_temp_word);
means free is called for NULL. You should not change the value of ...
2
votes
Accepted
Speller hash table - unload memory not working
Well, here's a really interesting scenario!
for (int i = 0; i < N; i++)
{
for (node *ptr = hashtable[i]; ptr != NULL; ptr = ptr->next)
{
free(ptr);
nodes_freed++;
}
}...
2
votes
Accepted
Pset5 SPELLER, CHECK50 errors and memory leak
Nothing after "MISSPELLED WORDS" in the check50 log indicates a segmentation fault. This line in unload
while (cursor == NULL)
is the culprit. It cannot free NULL. The equality test is wrong.
The ...
2
votes
speller valgrind "uninitialized error was created by heap allocation"
Blauelf is right. I had a similar problem which was being caused by not initialising the next field in the first node I was adding to the hash table. I fixed it by assigning NULL to the next field in ...
2
votes
CS50 pset5 program is free of memory errors valgrind tests failed;
You are getting that error because in your 'load' function, you are inicializing the value 'next' here: temp->next = table[index]; inside an 'if' condition. If you also set temp->next to NULL after ...
2
votes
Accepted
pset5 speller valgrind show leak in load function
Simply put, the unload function doesn't free anything. Worse, it loses the entire tree/trie. Here's why.
First, pointer is created and initialized and set to NULL.
Then the for loop starts. As the ...
2
votes
Accepted
Pset5: strcasecmp doesn't return 0 when given the same string input
Perhaps there's a slight oversight in your code. Look at the following:
lc_word[len + 1] = '\0';
Now, say that the word is "Cat". Length is 3 so len = 3. Remember that arrays start at 0,...
2
votes
Accepted
Speller Valgrind Issues
The problem lies in each of the malloc's in check and unload. All three node pointer vars that are created are used to process existing nodes, yet all three are initialized with malloc calls. They ...
2
votes
Accepted
PSET 5 Speller fails memory check
I will add comments for any missing braces I add or indentation I change or for code I would change like so // NOTE blah blah blah
#include <ctype.h>
#include <stdbool.h>
#include <...
2
votes
How to properly free memory in the following W3Schools c programming code demonstrating Queue Implementation using Linked Lists
Don't modify any of their methods.
The fix is entirely in main
You free the memory createQueue allocated into newQueue by free'ing newQueue at the end. Before you do that you use the dequeue function ...
1
vote
Accepted
Cannot understand why valgrind is giving error although check50 runs properly
It looks like your blur function is trying to access a non-existent pixel at image[height-1][width]. If so, that's probably not the only reference outside the boundary of image.
1
vote
Accepted
Confused with Memory Leak in pset5 Even Though the Problem is Fixed. What was wrong with my size function?
This number 143,065 from valgrind is 26 less than the number of words in the (large) dictionary. Which, not coincidentally, is the number of elements in table.
This table[i] = table[i]->next "...
1
vote
Accepted
Help with unloading my dic
Let's say the program loaded a dictionary of two words, "an" and "at". How many times will it try to free(hashtable[0])? By my accounting, twice, because the only node that gets free'd is hashtable[x]....
1
vote
Unknown memory leak on "check function" - CS50 Speller
Your code
node *checker = malloc(sizeof(node));
/* ... */
checker = hashtable[index];
means you allocate a new node, and then you throw away the only reference to that node, leaving this ...
1
vote
Accepted
PSET4 unload() don't work
What makes you think that the problem lies with unload? What's your thought process that leads you there? Or did you jump to that conclusion because that's where all the freeing is done? (Teachable ...
1
vote
Accepted
56 Bytes of leaked memory in speller.c pset5
In load, remove free(nodenew);. Completely, as requested by accepted answer https://cs50.stackexchange.com/a/30559/12099. The node is still in use.
If that doesn't solve the issue, add more data to ...
1
vote
Accepted
pset5 speller unload (trie) leaking memory
You need a second check in that large condition
((c == '\'') && (trav -> children[26] == NULL) || (c != '\'') && (trav -> children[c - 'a'] == NULL))
as it might happen that c =...
1
vote
How can I ensure I'm changing the reference, not a copy, in this C function?
Pass a pointer to the thing you want to change. If the thing is a pointer to a node, pass a pointer to this pointer to a node, using & operator. You will copy the pointer to the pointer, but that'...
1
vote
Accepted
Pset5 Memory leak with trie scructure
unloading is fine. load isn't.
free(current); refers to a node that's installed in your trie, so you may not free it. Remove that line.
current -> is_word = true; is the only thing that should be ...
1
vote
Accepted
Why C doesn't check for memory leaks automatically?
The compiler trusts the programmer. Some code might result in a memory leak depending on how you use it. Like malloc. If you look at the code, you would not know whether it results in a memory leak. ...
1
vote
Accepted
Pset 5 - valgrind errror because of memory leak
The problem lies in these two lines and the usage of fgets.
char *ptr = malloc(sizeof(char) * (LENGTH + 2));
for((ptr = fgets(ptr, 47, dictfile)); ptr != NULL; (ptr = fgets(ptr, 47, dictfile)))
{ ......
1
vote
Accepted
How/when to free this memory? (pset6/server)
Does valgrind return the leak if it finds index.html or index.php? I would predict this indexes would leak memory only if neither of those files is "found". Generally speaking, one would not change ...
1
vote
Accepted
CS50 PSET5 Memory Leak (updated)
I wanted to test your code so I took it from the link you provided.
When I tried to compile it, it did not compile. I had to fix two lines to get it to compile:
Line numbers are based on the code ...
1
vote
pset5. Can't trace memory leak
Function fopen() allocate memory for itself. Try without fclose(). You'll get leak of memory. You opened dictionary file and speller opened text file. So amount of memory will be = amount of nodes + ...
1
vote
Accepted
pset5. Can't trace memory leak
Prepare to slap head with hand!
If you were to run valgrind with the full dictionary and a large file, you'd probably see thousands of blocks lost. So, given this declaration,
typedef struct node
{
...
Only top scored, non community-wiki answers of a minimum length are eligible
Related Tags
memory-leak × 84pset5 × 53
valgrind × 37
speller × 31
c × 14
unload × 12
cs50x × 10
load × 10
pset4 × 7
memory × 7
recover × 6
pointers × 4
malloc × 4
check × 3
trie × 3
pset6 × 2
check50 × 2
recursion × 2
free × 2
speller-check × 2
allocation × 2
resize × 1
error × 1
dictionary × 1
filter × 1