16 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 ...
user avatar
15 votes
Accepted

How to fix the "conditional jump or move depends on uninitialized value" valgrind error?

The problem is mainly caused by the if statement on line 69 if (temp->word != NULL) { // some code } valgrind is angry because you never really initialized the member word of your struct ...
user avatar
  • 17.4k
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() ...
user avatar
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, ...
user avatar
  • 63.4k
7 votes
Accepted

How does valgrind work?

Valgrind basically runs your application in a "sandbox." While running in this sandbox, it is able to insert its own instructions to do advanced debugging and profiling. From the manual: Your ...
user avatar
  • 483
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 ...
user avatar
  • 20.7k
4 votes
Accepted

valgrind messages about "unititialised value(s)" - are they an issue?

You're totally correct. You have to initialize variables before asking for their values. Since a trie is an array of arrays, the root array can be initialized when declared like that node *root[26] =...
user avatar
  • 17.4k
3 votes

Valgrind error in PSET6

When implementing a recursive function, the base case should be written first because it's the first thing that should be executed to determine whether there should be one more recursive call or not! ...
user avatar
  • 17.4k
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 ...
user avatar
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.
user avatar
  • 20.7k
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,...
user avatar
  • 18.4k
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. ...
user avatar
  • 5,172
2 votes

Correct use of fopen, fclose, file pointers

OK, so it turns out there was already an answer to this on Reddit. The problem was that I was declaring my pointer again, instead of just reassigning. In other words, I was doing: FILE* img = fopen(....
user avatar
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 ...
user avatar
  • 264
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 ...
user avatar
  • 63.4k
2 votes
Accepted

Valgrind error in PSET6

The cause you have pasted means that you are checking the value of a variable you didn't previously specify (most likely unloader -> children[i] != NULL). When creating a new node, you should ...
user avatar
  • 332
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 ...
user avatar
  • 1,415
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 ...
user avatar
  • 63.4k
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 ...
user avatar
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 ...
user avatar
  • 18.4k
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.
user avatar
  • 314
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 ...
user avatar
  • 63.4k
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 ...
user avatar
  • 63.4k
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 ...
user avatar
  • 63.4k
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); } ...
user avatar
  • 63.4k
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. ...
user avatar
  • 18.4k
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, ...
user avatar
  • 63.4k
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 ...
user avatar
  • 18.4k
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 ...
user avatar
  • 20.7k
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.
user avatar
  • 18.4k

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