3
votes
PSET5: Why is my code working without fully implemented Unload function
Totally awesome that you are asking the question even though it passed check50! Kudos.
Notice this line Usage: speller [dictionary] text in the valgrind report. Speller didn't really run. You called ...
3
votes
Accepted
Pset5 Memory leak in unload()
Complicated code in terms of memory management. This set of problems deals with the traditionally more difficult concepts of C programming, so we need a good theoretical basis for dealing with them. ...
2
votes
Accepted
14 allocs ,13 frees in unload()
Ok, a couple of notes first to clear the field. Starting from easy:
According to man 3 free:
The free() function frees the memory space pointed to by ptr, which must have been returned by a ...
2
votes
14 allocs ,13 frees in unload()
Check that you've closed your dictionary file.
Passing temp to free_memory() might not change temp to NULL. (Hopefully someone smarter can confirm via comments, or a better answer)
bool unload(void)
...
2
votes
Accepted
PSET5 - UNLOAD - Trie, Valgrind Errors
Your code looks mostly good. Although you can return true from your recursive freeTrie() function and then in your unload() function just call freeTrie() on your root node. That's it.
You don't need ...
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
Problem in my unload function (double free or corruption)
one block of memory can be pointed at by many pointers. this is exactly what happens when you allocate memory for one pointer, then set the value of another pointer to be the same as the first pointer'...
2
votes
Accepted
Pset5 trie unload -recursive function does not free memory
Think carefully about what the code is doing. It checks if a pointer is null, and if so, it will free that node. In other words, it will free a nonexistent node - a do nothing operation. OR, if the ...
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 2017 unload() trie segmentation fault and undefined behavior
Couldn't do a full, in-depth analysis because I would need to see the node struct declaration and all of the involved functions. However, here's a somewhat common issue. Look at the following code:
...
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
PSET5 - Valgrind error - no enough bytes are being freed
The nodes created here if (!create_new_node(palabra)) (one for each dictionary word) are never freed.
1
vote
Accepted
pset5 (trie) valgrind memory leak
Without even looking at anything but this:
(if (start->child[i] != NULL))
I would ask if start actually exists at this point in the execution. I'll look at the code and edit my answer if/when I ...
1
vote
PSet5: Segfault in unload
First, the while loop in unload makes no sense, since root is never changed, you would enter an infinite loop trying to free the same trie over and over (probably running into another segfault on ...
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
Problem in unload
The code looks correct (assuming children is a node[27]).
Either that's not the code you submitted, or you have another problem, most likely uninitialised memory (memory by malloc may initially ...
1
vote
Accepted
Need help with recursion for unload in pset5
Did you make dictionary or make speller? The latter is correct, the former will produce the error you saw, along with about 20 relocation errors. This almost certainly has nothing to do with your ...
1
vote
Accepted
pset5 unloading tries uncomplete, 244 bytes in 1 block still reachable
@DinoCoderSaurus called it in the comments. Your destroy() function is calling itself recursively, and the comments indicate that you intend to free heap memory somewhere in there. Yet there is no ...
1
vote
Accepted
Unload function double free or corruption
The problem lies in these two lines:
current = current->children[i];
unloadreal(current);
Think about what happens after the recursive calls start to return. current is no longer ...
1
vote
Segmentation error on PSET5 unload function
The problem was the else statement. Using a while loop was fine, but the implementation was faulty.
Think about what happens because the index++ was put in an else clause. When the code executes, if ...
1
vote
Accepted
Segmentation error on PSET5 unload function
I believe what went wrong in your first clear function was an issue of scope. In your first function, you declared index outside of your while loop, so when the recursion kicks in, the loop increments ...
1
vote
Accepted
Pset5 Last frown to turn upside down!
Do not access new_node->next before testing for new_node == NULL. If the first one hasn't segfaulted, the second one won't match.
Your error is related to the unload function. Your while loop will ...
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
Pset5 Unload Giving Double Free or Corruption error
You have a tree structure (yes, a trie, but that's more a variation), and I don't see how you intend to free all nodes.
One misconception you seem to have is that freeing something makes the pointer ...
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 unload trie
You free the node even if it has children. You should first destroy any non-NULL children, and then free the current node. No while loop required, just a single loop over all the children, calling ...
1
vote
Accepted
Pset5 Problem with Valgrind
Your problem arises when you read an apostrophe in load(). You have:
c = fgetc(dict);
if(isalpha(c) || c == '\'')
{
// Checks if the node already exists or not
if(trav->children[c-96] == ...
1
vote
Problem in my unload function (double free or corruption)
You are trying to free the same node twice. At the end of your freenode() function, you have the following code: if(n != NULL) free(n);. Remember that this is a recursive function. freenode() will ...
1
vote
I want to unload cs50 appliance from my machine
My appliance is stored in /Documents/Virtual Machines (I expect that was the default when I installed VMWare Fusion.)
If it's not there, use Finder and search for kind: vmware and it should show ...
Only top scored, non community-wiki answers of a minimum length are eligible
Related Tags
unload × 109pset5 × 87
speller × 53
valgrind × 28
load × 14
trie × 13
memory-leak × 13
recursion × 10
segmentation-fault × 8
pset6 × 7
free × 7
dictionary × 6
segfault × 6
cs50x × 4
c × 4
check × 4
pointers × 4
pset4 × 3
check50 × 2
memory × 2
seg × 2
memorystillreachable × 2
appliance × 1
error × 1
hash-table × 1