title: HEAP CORRUPTION DETECTED when i try to free(void * key)
body: <p>Having a problem with freeing memory in the end of the program.
  This is an exercise from school, implementation of a binary-tree with ADT and specific implementation with data-type char.</p>
  
  <p>freeing code:</p>
  
  <pre><code>void free_tree(TreeNode *root){
  TreeNode *cur;
  if (!root) return;
  else{
  cur = root;
  free_tree(cur-&gt;left);
  free_tree(cur-&gt;right);
  free(cur-&gt;key);               //throws an error!
  free(cur);
  } }
  </code></pre>
  
  <p>This is where i malloc for the key itself (problem is probably here):</p>
  
  <pre><code>puts("Please enter a value for key of new node");
  _flushall();
  scanf("%s",&amp;buffer);
  user_input = (char *) malloc(sizeof(char)*(strlen(buffer)+1));
  strcpy(user_input,buffer);
  user_input[strlen(buffer)+1] = '\0';
  p_node = create_tree_node(user_input);   //this function append the new data to a new node, returns *TreeNode
  insert_node_by_value(&amp;root,p_node,str_comp);
  break;
  </code></pre>
  
  <p>And this is the error I get:</p>
  
  <p><img src="https://i.stack.imgur.com/b5Rvv.jpg" alt="Error Message"></p>
  
  <p>BTW Freeing the node themselves is working fine!</p>
  
  <p>I'll appreciate your help and any tips and comments about the functionality of the code.</p>
  
  <p>Full code paste of functions.c can be found here: 
  <a href="http://pastebin.com/TqaNK5v8" rel="nofollow noreferrer">http://pastebin.com/TqaNK5v8</a> - functions</p>