Circular buffer implementation using linked list
Bug
When you dequeue the last element, this code will run with p_size being 1:

   if (p_size&gt;0)
    {   
        val=read-&gt;item;
        read=read-&gt;next;
        free(ptr);
        p_size--;
        printf(&quot;removed %d\n&quot;,val);
    }


The result of this code is that the last element will be freed, but read and write will still be pointing at it, because the list was circular.  Then the next time you call enqueue(), it will use those stale pointers to add to the list.
To fix this problem, you should clear the pointers to NULL when you dequeue the last element.