Can anyone please tell me why this

Code:
void InsertNode(NODE *pNode, NODE *pAfter)
{              

   pNode->pNext = pAfter->pNext;
   pNode->pPrev = pAfter;
  
  if (pAfter->pNext != NULL)
      pAfter->pNext->pPrev = pNode;
  else
      pTail = pNode;
      pAfter->pNext = pNode;
  
}
decides it is going to exit the program?

It is supposed to insert pNode into the linked list after pAfter but it is not working, it just exits every single time. grrrr. Any help would be greatly appreciated