double free or corruption (fasttop)

The problem is here:

        temp2=first;

Basically, when you free temp2, you free first, not the memory allocated here:

        temp2=(NODE *)malloc(sizeof(NODE));

, which remains a memory leak, because after the assignment it can’t be freed anymore.

Also, your code has probably some more problems (one is that you shouldn’t use fflush on an input stream), but without some more details, it’s impossible to tell.

Leave a Comment