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
Memory allocation: recommended practices
I'm not sure you needed to learn about pointers and memory management in order to solve hacker 2. I think you've gone a little bit far. However, I'm gonna try answering your questions.
A pointer is ...
2
votes
pset 6 memory leaks
I am also a newbie at programming but hope I can help. I've been stuck with the same problem for some time and just solved with some help.
The 52 bytes is the size of one node not freed which in this ...
2
votes
Accepted
Why Am I Having a Memory Leak?
This question was also posed on Facebook by you here: https://www.facebook.com/groups/cs50/permalink/343562319124153/
In a nutshell, GetString() mallocs space to hold the character array that you ...
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
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
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 ...
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
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
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
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
pset 5 memory leak - how struct definition may be related
Your valgrind results:
==3069== at 0x402A17C: malloc (in /usr/lib/valgrind/vgpreload_memcheck-
x86-linux.so)
==3069== by 0x8049087: check (dictionary.c:59)
==3069== by 0x8048B6D: main (...
1
vote
Accepted
Can't make Valgrind happy in Speller (pset5)
I think the main problem is that you're freeing new_node->word and new_node at the end of each iteration. here's a demonstration:
int *ptr0 = malloc(sizeof(int));
*ptr0 = 10; // stores 10 into ...
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
{
...
1
vote
Accepted
pset5. Can unload words in dictionary but memory is definitely and indirectly lost
fclose the dict at the end of load, the file should be open only for the duration of reading. Otherwise, unload looks fine.
In your hash function
return (c != '\'')? c - 'a' : CHILDREN_LENGTH;
...
1
vote
Accepted
PSET5: memory leak
If you free the root node in load, you cannot use it in check. You allocate "lots of " child nodes, but only "free" the last one. You absolutely can test that load works before implementing unload, ...
1
vote
Accepted
Pset5 all words are misspelled and Valgrind reports 15 errors
In check:
wordcopy = malloc(wordlength * sizeof(char)); allocates too little space, should be malloc((wordlength+1) * sizeof(char));, and don't forget the wordcopy[wordlength] = '\0'; null terminator,...
1
vote
Pset5 Speller Memory Leak
I think you should return false if file is NULL, not just dictionary (the latter is highly unlikey given the surrounding code, the former might happen if the file is not where you expect it to be)
...
1
vote
Pset5 Speller Memory Leak
568 bytes in 1 block is usually an open file pointer that hasn't been closed.
As for the rest, I can't tell from the code posted, or more specifically, not posted. The posted code looks like it ...
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 ...
Only top scored, non community-wiki answers of a minimum length are eligible
Related Tags
memory-leak × 71pset5 × 49
valgrind × 35
speller × 22
unload × 12
load × 11
c × 7
memory × 5
pset4 × 4
malloc × 4
recover × 3
cs50x × 3
check × 3
trie × 3
pointers × 3
pset6 × 2
recursion × 2
free × 2
speller-check × 2
allocation × 2
resize × 1
error × 1
dictionary × 1
filter × 1
array × 1