title: Uninitialized value was created by a heap allocation
body: <p>I'm trying to implement a dictionary of words using a hash table, so I need to have it global, and in one of my header files I declare it</p>
  
  <pre><code>extern node** dictionary;
  </code></pre>
  
  <p>Where node is</p>
  
  <pre><code>typedef struct node
  {
      char* word;
      struct node* next;
  } node;
  </code></pre>
  
  <p>Then in another file in which functions are defined I include the header which has the dictionary declaration, and also I add at the top</p>
  
  <pre><code>node** dictionary;
  </code></pre>
  
  <p>Then in the function which actually loads the dictionary I first allocate memory for the linked lists which will make the hash table</p>
  
  <pre><code>bool load(const char* dict_file)
  {
      dictionary = malloc(sizeof(node*) * LISTS);
  
      FILE* dict = fopen(dict_file, "r");
  
      if(dict == NULL)
          return false;
  
      char buffer[MAX_LEN + 2];
  
      size_dict = 0;
  
      while(fgets(buffer, MAX_LEN + 2, dict) != NULL)
      {
          node* new_node = malloc(sizeof(node));
  
          int len = strlen(buffer);
  
          new_node-&gt;word = malloc(sizeof(char) * (len));
  
          //avoid \n
          for(int i = 0; i &lt; len - 1; i++)
              new_node-&gt;word[i] = buffer[i];
  
          new_node-&gt;word[len - 1] = '\0';
  
          new_node-&gt;next = NULL;
  
          int index = hash(buffer);
  
          new_node-&gt;next = dictionary[index];
  
          dictionary[index] = new_node;
  
          size_dict++;
      }
  
      if (ferror(dict))
      {
          fclose(dict);
          return false;
      }
  
      fclose(dict);
      return true;
  }
  </code></pre>
  
  <p>So the program works fine, I then free all the allocated memory for strings and nodes and when I run valgrind(a debugger which detects memory leaks) it says no memory leaks are possible, but it says that there is an error <i>Uninitilised value was created by a heap allocation</i> and redirects me to that exact line where I'm allocating memory for <code>dictionary</code> the exact first line of the load function which I've written above.<br>What am I doing wrong? I guess the way I use <code>dictionary</code> globally is wrong, so can anybody suggest some other way of keeping it global and avoid this error?</p>