19
votes
Accepted
Conditional jump or move depends on uninitialised value(s)
The problem is in the conditions right?
specifically in the node, pointed to by node* cur
Now it's a problem because the node, node* cur is pointing to is "uninitialized"
When we malloc something ...
13
votes
Conditional jump or move depends on uninitialised value(s)
I had a ton of errors like that, too...
But ALL these errors disappeared, when I changed only 4 single characters in my code!
Here's how:
I simply used calloc() in place of malloc()!
calloc() ...
8
votes
Accepted
(pset5) valgrind - 1 block not freed
Hmmm..... 568 bytes in 1 block.... sounds like a file pointer.
Did we forget to close an open file somewhere???? ;-)
Side note: valgrind usually tells you how you can get more information, ...
5
votes
Accepted
Pset5 : Speller: Valgrind : Blocks are still reachable
568 bytes happens to be the size of a structure allocated in fopen and freed in fclose. It seems you don't call fclose on reaching EOF. I don't get that if/else at the end of load, since you can leave ...
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
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 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
Pset 5 - Big Board error but program passes check50 and no valgrind errors
checking for valgrind errors...
Invalid read of size 1: (file: dictionary.c, line: 76)
So what's line 76 on dictionary.c?
Also, based on the time your spell-checker took for that one text,...
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 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
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
Accepted
Can't free malloc used in check
Well, it seems to me that if you want to free that particular malloc, you need to have two free() statements, one immediately before each return so that no matter how you exit, it gets freed. For the ...
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
CS50 PSET5 Trie Segmentation Fault
As noted in the comments, root is not declared globally. It is declared as a local var in both load and check. By declaring it locally in load, the local var root is destroyed when load ends. That ...
2
votes
Accepted
pset5 check function and const char* word
Can't tell you exactly what's happening without seeing your entire code, but one thing I can tell you right away is that you're forgetting to allocate space for the null terminator when you only ...
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
Pset5 - Speller - Load (loading only 1 word in dictionary)
It seems to me that because your hash function is not case-insensitive all of the words with capital letters get hashed to a different location (h) before you get to use strcasecmp.
2
votes
Accepted
Pset5 Speller - seems working but fails check50
As always, it's most helpful to post actual results in the question. I ran the code and found the following result in valgrind:
==1350==
==1350== HEAP SUMMARY:
==1350== in use at exit: 568 bytes ...
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
Valgrind output help with speller
valgrind has figured that the variable you pass to tolower (declared on line 21 in speller.c, which is strange, as that's code that should be correct) might not have been initialised. This might ...
2
votes
Accepted
Pset5 Speller Invalid read of size 8
I see two issues with unload. First, when it finishes, it returns false instead of true.
Now on to the main issue. Look at this code at the end of load.
if (feof(file))
{
free(newnode);
}
...
2
votes
Accepted
Pset5 - Valgrind causes 9544106 errors, Uninitialised value was created by a heap allocation
The issue lies in how you are initializing your nodes.
for (int i=0; i<27; i++)
{
trav->next[x]=NULL;
}
What is x on that line? Pay special attention to your counting variable in the loop.
...
2
votes
Accepted
Memory leak and erratic behavior with code
The main problem lies in your check function. The for loop setup increments l on each pass. Unfortunately, the code is also incrementing l inside the loop, so every other letter in a word is skipped, ...
2
votes
Accepted
PSET5 check50 Speller HELP please!
Valgrind is reporting leaked memory when I run it, and it comes from this line in check:
//allocating space for cursor
node *cursor = malloc(sizeof(node));
cursor is a pointer. It doesn't need any ...
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 running valgrind says I'm accessing 8 bytes of memory that isn't mine
Why are you freeing new_node inside the load function? All of your nodes will be freed in unload so by freeing the last new node in load, unload hits memory that is no longer yours.
2
votes
Accepted
valgrind tutorial?
You'd prepend valgrind to whatever you would usually type. If you use ./speller texts/alice.txt, you would write valgrind ./speller texts/alice.txt instead, similar to how debug50 and other tools are ...
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
Valgrind says no leaks possible. However has lots of errors
Valgrind is telling you where the memory in question is being allocated, not where the problem lies.
When valgrind says that memory is still reachable, its really saying that it wasn't freed before ...
Only top scored, non community-wiki answers of a minimum length are eligible
Related Tags
valgrind × 223pset5 × 145
speller × 102
memory-leak × 38
unload × 28
pset4 × 24
load × 22
memory × 18
recover × 16
cs50x × 16
dictionary × 15
check50 × 13
c × 12
segmentation-fault × 12
trie × 12
pset6 × 9
free × 9
error × 8
malloc × 6
check × 5
pointers × 5
server × 3
resize × 2
hash-table × 2
fails-check50-but-works × 2