title: Error invalid pointer when I use free() to free a malloced pointer
body: <p>I can't free this pointer after using it in my function.
  It gives me this error message. The function should check a trie dictionary for if a word is spelled right or wrong. And root is the first trie node. </p>
  
  <blockquote>
    <p>Error in `./speller': free(): invalid pointer: 0x00007fe53a80d848</p>
  </blockquote>
  
  <p>Here's the function:</p>
  
  <pre><code>bool check(const char *word)
  {
      int pos=0;
      int path;
      char wordChar=*(word+pos);
      wordTriePtr cursor=(wordTriePtr) malloc(sizeof(wordTrie));
      cursor=root;
      while(wordChar!='\0')
      {
          path=determinePath(wordChar);
          if(cursor-&gt;children[path]==NULL)
          {
              free(cursor);
              return false;
          }
          else
              cursor = cursor-&gt;children[path];
  
          wordChar=*(word+(++pos));
      }
      if(cursor-&gt;isThisWord==true)
      {
          free(cursor);
          return true;
      }
      else
      {
          free(cursor);
          return false;
      }
  }
  </code></pre>
  
  <p>What am I doing wrong?</p>