corby -4 Junior Poster

i have this code for adding a node after the previous node, but valgrind is saying that there is a memory leak of 16 bytes, can someone please help me identify where the leak is? i think i didnt assign a null pointer somewhere but im not sure exactly where

struct Node *addAfter(struct List *list, struct Node *prevNode, void *data)
{
        struct Node *temp;
        temp = (struct Node *)malloc(sizeof(struct Node));
        if (temp == NULL )
        {
                perror("malloc returned NULL");
                return NULL;
        }else
        {
                temp->data = data;
                if(prevNode == NULL)
                {
                        prevNode = addFront(list, temp->data);
                        prevNode->next = NULL;
                }else
                {
                        while(prevNode->next != NULL)
                        {
                                prevNode = prevNode->next;
                        }

                        temp->next = NULL;
                        prevNode->next = temp;
                }

                return prevNode;
        }
};
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.