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
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.
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
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 ...
2
votes
Accepted
Recursion Destroy Singly linked List, memory leak?
You have only implemented part of your goal. This code will walk down a linked list to the last element, but will only free memory when it finds that the next element is null, i.e., it is at the end ...
2
votes
Freeing temp node in unload pset5
It turned out one of my problems was I was freeing the root node after the recursive call, but the call itself frees the node, so that was causing a double free error.
The actual error was that for ...
2
votes
Accepted
GetString() & Dynamic Memory Allocation
Yes it's true that for simplicity's sake, in the first psets, we din't free() the strings allocated by GetString() and that caused memory leaks.
Nevertheless, most modern operating systems can see ...
2
votes
Pset5 unload trie 244 bytes lost
Your code isn't freeing recursively. It should keep on going down the tree while children[i]!=NULL, only freeing the node when that condition isn't met anymore. It then returns up the tree, freeing ...
2
votes
Accepted
char* and read-only memory
Yes and no. Yes it is stored to memory, but the way in which it is declared has no memory leaks (try making a test file and running valgrind to see for yourself).
What does cause a memory leak is ...
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
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
Problems with letters "a" and "I" misspellings
TL; DR:
This looks like a memory leak.
Remove:
node *tableindex = malloc(sizeof(node));
tableindex = hashtable[ind];
...
free(tableindex);
Add:
node *tableindex = hashtable[ind];
...
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
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
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
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: 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 ...
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
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
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
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
Accepted
Pset5: valgrind still reachable
Take a close look at the code for free_node()
for (int i = 0; i < 27; i++)
{
if (cursor -> children[i] != NULL)
{
cursor = cursor -> children[i];
return free_node(...
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 × 81pset5 × 52
valgrind × 38
speller × 30
unload × 13
c × 11
load × 11
memory × 7
pset4 × 6
cs50x × 6
recover × 5
pointers × 5
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