title: double free or corruption (fasttop)
body: <p>The following section of my code gives me this messege when executing <strong>* glibc detected <em></strong> ./a.out: double free or corruption (fasttop): 0x08e065d0 *</em>*</p>
  
  <p>i have gone through the code many times but i cant clealry see how i am misusing the <code>free (temp2)</code></p>
  
  <pre><code>bool found= false;
  int x=0;
  for ( x=0; x&lt;=312500; x++)
  {
      while (count &lt;=32)
      {
          fscanf (file, "%d", &amp;temp-&gt;num);  
  
          temp-&gt;ptr=NULL;
  
          newNode = (NODE *)malloc(sizeof(NODE));
          newNode-&gt;num=temp-&gt;num;
          newNode-&gt;ptr=NULL;
  
          if (first != NULL)
          {
              temp2=(NODE *)malloc(sizeof(NODE));
  
              temp2=first;
              while (temp2 != NULL &amp;&amp; !found)
              {
                  if (temp2-&gt;num == newNode-&gt;num) 
                  {found=true;}
  
                  temp2= temp2-&gt;ptr;
              }
  
              free(temp2);
  
              if (!found)
              { 
                  last-&gt;ptr=newNode;
                  last=newNode;
                  count=count+1;
              }   
          }   
          else  
          {
              first = newNode;
              last = newNode;
              count=count+1;
          }
  
          fflush(stdin);
      }
  </code></pre>