954,492 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

question about linked list

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;
}
};

corby
Junior Poster
118 posts since Feb 2010
Reputation Points: 6
Solved Threads: 5
 

This question has already been solved

Post: Markdown Syntax: Formatting Help
You
View similar articles that have also been tagged: