Skip to main content
4 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. ...
MARS's user avatar
  • 5,179
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 ...
DinoCoderSaurus's user avatar
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 ...
Cliff B's user avatar
  • 69.1k
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 ...
Cliff B's user avatar
  • 69.1k
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: ...
Cliff B's user avatar
  • 69.1k
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 ...
ronga's user avatar
  • 1,415
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.
DinoCoderSaurus's user avatar
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 ...
Cliff B's user avatar
  • 69.1k
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 ...
hotwebmatter's user avatar
  • 3,050
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 ...
Cliff B's user avatar
  • 69.1k
1 vote
Accepted

PSET5 Unload() recursive sub-function causes 112 bytes to leak - why?

Actually, it probably leaks a lot more than that, depending on the size of the linked list. The first version is an either/or. It will either free a node or move to the next node. In practice, that ...
Cliff B's user avatar
  • 69.1k
1 vote
Accepted

Help with PSet 5 2020 - Speller - Check & Unload Functions (EDIT: logic error in Load Function)

This is a good lesson for all! I can completely understand your frustration!!! This is a very interesting problem because it is a pure logic error. Most problems on this forum are due to syntax or ...
Cliff B's user avatar
  • 69.1k
1 vote
Accepted

Speller seg faults in unload function

Here's the issue: if (cursor->next != NULL) { while (cursor->next != NULL) The problem is that if cursor is ever null, cursor->next doesn't exist. That will cause a seg fault. ...
Cliff B's user avatar
  • 69.1k
1 vote
Accepted

pset5 speller unload function

First version makes little sense to me. In second version, you stop when current->next becomes NULL. But first, if current is NULL (small dict would have that), you get a segmentation fault. ...
Blauelf's user avatar
  • 21k
1 vote
Accepted

Stuck with Unload using trie

Your call to seek_last (by this name I'm not sure what it is supposed to do) will trigger a cascade of recursive calls that will eventually result in freeing one node. You need to remember the path ...
Blauelf's user avatar
  • 21k
1 vote
Accepted

dictionary.c trie: setting variable to NULL doesn't set element to NULL

The simple answer is that you set the child pointer to NULL by setting the child pointer to NULL. Remember that when you say node *traverse_node you are declaring a pointer that holds an address. ...
curiouskiwi's user avatar
  • 18.7k
1 vote

valgrind in speller unload says I am using a variable without a value, when I assign it in the previous line

The error probably has its origin in load. Did you explicitly assign a value to every hashtable[i]->next pointer?
curiouskiwi's user avatar
  • 18.7k
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 ...
Cliff B's user avatar
  • 69.1k
1 vote
Accepted

Unload works on small dictionary, but not on large? (speller.c / hash table method)

Hehe, put the word "zebra" in your small dictionary and see if it still works! ;-) I'm assuming that hashtable[25] represents words that start with 'z'. I'll wager that your small dictionary ...
Cliff B's user avatar
  • 69.1k
1 vote
Accepted

Speller (pset 4 2019) - Can't fix memory leak in hashtable

Have a look at your unload. You are returning true the first time the cursor is null. So your loop doesn't end up checking all of the table. Don't return true until the very end.
curiouskiwi's user avatar
  • 18.7k
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 ...
Cliff B's user avatar
  • 69.1k
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 ...
Blauelf's user avatar
  • 21k
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 ...
Blauelf's user avatar
  • 21k
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 ...
Blauelf's user avatar
  • 21k
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 ...
Cliff B's user avatar
  • 69.1k
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 ...
Edward Lee's user avatar
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 ...
Blauelf's user avatar
  • 21k
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 =...
Blauelf's user avatar
  • 21k
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 ...
Blauelf's user avatar
  • 21k
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 + ...
Silkov Evgen's user avatar

Only top scored, non community-wiki answers of a minimum length are eligible