Hi
I have a linked list that can store two types of object. It's kinda weird and hackish but it seems to work.
Code:
struct Node
{
    struct Node *pNext;
    struct Node *pPrev;
    int iType;
};
struct Type1
{
    struct Node *pNext;
    struct Node *pPrev;
    int iType;
    
    float f1, f2;
};
struct Type2
{
    struct Node *pNext;
    struct Node *pPrev;
    int iType;
    
    int x, y, z;
};
Code:
struct Node *pRoot;
When iterating through this list, a struct Node * is used. The object is identified by its iType field, then the pointer is converted to a struct Type1 * or a struct Type2 * to access the other members.

The deallocation of the linked list happens like this:
Code:
void DeleteNode(struct Node *pNode)
{
    if(pNode->pPrev) pNode->pPrev->pNext = pNode->pNext;
    if(pNode->pNext) pNode->pNext->pPrev = pNode->pPrev;
    free(pNode);
}    
void EmptyList()
{
    while(pRoot->pNext) DeleteNode(pRoot->pNext);
}

/// here
EmptyList();
free(pRoot);
My question is: doesn't this cause a memory leak? I could imagine that in the DeleteNode() function only the first three members get properly deallocated because the pointer is of type struct Node *.